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.
import sys
input = sys.stdin.buffer.readline 

def finder(L, x):
    if x < L[0][0]:
        return -1
    if x > L[-1][0]:
        return -1
    if x==L[0][0]:
        return 0
    if x==L[-1][0]:
        return len(L)-1
    s = 0
    e = len(L)-1
    while s+1 < e:
        m = (s+e)//2
        if L[m][0]==x:
            return m
        elif L[m][0] < x:
            s, e = m, e
        else:
            s, e = s, m
    return -1

def find_root(root_dict, x):
    L = []
    while x != root_dict[x]:
        L.append(x)
        x = root_dict[x]
    for y in L:
        root_dict[y] = x
    return x

def process(n, m, A):
    A.sort()
    x, y = A[0]
    curr = x
    curr1 = []
    L = []
    
    for i in range(m):
        x, y = A[i]
        if x > curr:
            L.append([curr, curr1])
            curr = x
            curr1 = []
        if x==curr:
            curr1.append([y, i])
    L.append([curr, curr1])
    root_dict = [i for i in range(m)]
    m1 = len(L)
    for i in range(m1):
        x = L[i][0]
        m2 = len(L[i][1])
        for j in range(m2):
            y, I = L[i][1][j]
            if j > 0 and L[i][1][j-1][0]==y-1:
                I2 = L[i][1][j-1][1]
                rootI = find_root(root_dict, I)
                rootI2 = find_root(root_dict, I2)
                root_dict[rootI] = rootI2 
            if j < m2-1 and L[i][1][j+1][0]==y+1:
                I2 = L[i][1][j+1][1]
                rootI = find_root(root_dict, I)
                rootI2 = find_root(root_dict, I2)
                root_dict[rootI] = rootI2 
            if i > 0 and L[i-1][0]==x-1:
                for y2 in [y-1, y, y+1]:
                    i2 = finder(L[i-1][1], y2)
                    if i2 != -1:
                        I2 = L[i-1][1][i2][1]
                        rootI = find_root(root_dict, I)
                        rootI2 = find_root(root_dict, I2)
                        root_dict[rootI] = rootI2 
    roots = [[] for i in range(m)]
    for i in range(m):
        i1 = find_root(root_dict, i)
        x, y = A[i]
        roots[i1].append([x, y])
    for i in range(m):
        if len(roots[i]) > 0:
            walls = [0, 0, 0, 0]
            L2 = sorted(roots[i], key=lambda a: a[0])
            if L2[0][0]==1:
                walls[0] = 1
            if L2[-1][0]==n:
                walls[1] = 1
            L2 = sorted(roots[i], key=lambda a: a[1])
            if L2[0][1]==1:
                walls[2] = 1
            if L2[-1][1]==n:
                walls[3] = 1
            """
                 2
            0        1
                3
            """
            if walls[0]==1 and walls[2]==1:
                sys.stdout.write('-1\n')
                return
            if walls[0]==1 and walls[1]==1:
                sys.stdout.write('-1\n')
                return
            if walls[1]==1 and walls[3]==1:
                sys.stdout.write('-1\n')
                return
            if walls[2]==1  and walls[3]==1:
                sys.stdout.write('-1\n')
                return
    sys.stdout.write(f'{2*n-2}\n')
    return
            
                
            
                
    
            
    

        
        
    
n, m = [int(x) for x in input().split()]
A = []
for i in range(m):
    x, y = [int(x) for x in input().split()]
    A.append([x, y])
process(n, m, A)