Iahub got lost in a very big desert. The desert can be represented as a *n* × *n* square matrix, where each cell is a zone of the desert. The cell (*i*, *j*) represents the cell at row *i* and column *j* (1 ≤ *i*, *j* ≤ *n*). Iahub can go from one cell (*i*, *j*) only down or right, that is to cells (*i* + 1, *j*) or (*i*, *j* + 1). 

Also, there are *m* cells that are occupied by volcanoes, which Iahub cannot enter. 

Iahub is initially at cell (1, 1) and he needs to travel to cell (*n*, *n*). Knowing that Iahub needs 1 second to travel from one cell to another, find the minimum time in which he can arrive in cell (*n*, *n*).
The first line contains two integers *n* (1 ≤ *n* ≤ 10<sup class="upper-index">9</sup>) and *m* (1 ≤ *m* ≤ 10<sup class="upper-index">5</sup>). Each of the next *m* lines contains a pair of integers, *x* and *y* (1 ≤ *x*, *y* ≤ *n*), representing the coordinates of the volcanoes.

Consider matrix rows are numbered from 1 to *n* from top to bottom, and matrix columns are numbered from 1 to *n* from left to right. There is no volcano in cell (1, 1). No two volcanoes occupy the same location.
# n, m = (4, 2)
# v = [(1, 3), (1, 4)]

# # v = []

# n, m = (7, 8)
# v =[(1, 6), (2, 6), (3, 5), (3, 6), (4, 3), (5, 1), (5, 2), (5, 3)]

# n, m = (2, 2)
# v = [(1, 2), (2, 1)]

# n = input()
# a = [map(int, raw_input().split()) for i in xrange(n)]
# print sum([[j[1] for j in a].count(i[0]) for i in a])

# import sys
# data = sys.stdin.readlines()

# ri = lambda : int(sys.stdin.readline().strip())
# rai = lambda : map(int, sys.stdin.readline().strip().split())

import sys
read_ints = lambda : map(int, sys.stdin.readline().split())
n, m = read_ints()
v = [(read_ints()) for i in range(m)]

e = n*2-2
# print("e : ", e)
# print("n : ", n)
# x, y = 1, 1

r = 0

def go(x, y, d):
    # if (x, y) is (n, n) and d is e: return d
    global r
    if x > n or y > n or (x, y) in v: return
    d += 1
    if d > r:
        r = d
    go(x+1, y, d) 
    go(x, y+1, d)

go(1, 1, -1)

# while ((x, y) is not (n, n) or (x, y) not in v):

# print (e, r)
if e is r:
    print(r)
else:
    print(-1)