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).

Input

The first line contains two integers n (1 ≤ n ≤ 109) and m (1 ≤ m ≤ 105). 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. 

Output

Print one integer, the minimum time in which Iahub can arrive at cell (n, n). If no solution exists (there is no path to the final cell), print -1.

Examples

Input

4 2
1 3
1 4


Output

6


Input

7 8
1 6
2 6
3 5
3 6
4 3
5 1
5 2
5 3


Output

12


Input

2 2
1 2
2 1


Output

-1

Note

Consider the first sample. A possible road is: (1, 1) →  (1, 2) →  (2, 2) →  (2, 3) →  (3, 3) →  (3, 4) →  (4, 4).
import sun.misc.Compare;

import java.io.*;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.util.*;
import java.math.BigInteger;

import static java.lang.Math.*;
import static java.math.BigInteger.*;
import static java.util.Arrays.*;


public class Main{

    void run(){
        boolean oj = System.getProperty("ONLINE_JUDGE") != null;
//        boolean oj = true;
        try{
            if( oj ){
                sc  = new FastScanner( new InputStreamReader(System.in  ) );
                out = new PrintWriter(   new OutputStreamWriter(System.out) );
            } else{
                sc  = new FastScanner(new FileReader("in.txt") );
//                sc  = new FastScanner(new FileReader("D:\\JavaOlymp\\FatalError\\output.txt") );
                out = new PrintWriter(   new FileWriter("out.txt") );
            }
        } catch (Exception e) {
            System.exit(-1);
        }
//        long tB = System.currentTimeMillis();
        solve();
//        if( !oj ) System.err.println( "Time: " + (System.currentTimeMillis()-tB)/1e3 );
        out.flush();
    }

    class FastScanner{
        BufferedReader br;
        StringTokenizer st = new StringTokenizer("");
        FastScanner( InputStreamReader a ){
            br = new BufferedReader(a);
        }
        FastScanner( FileReader a ){
            br = new BufferedReader(a);
        }
        String next(){
            while( !st.hasMoreTokens() )
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    return null;
                }
            return st.nextToken();
        }
        String readLine(){
            try {
                return br.readLine();
            } catch (Exception e) {
                return null;
            }
        }
        int nextInt(){ return Integer.parseInt(next()); }
    }

    FastScanner sc;
    PrintWriter out;



    public static void main(String[] args){
//        new Main().run();
        new Thread( null, new Runnable() {
            @Override
            public void run() {
                new Main().run();
            }
            //}, "LOL", 256L * 1024 * 1024 / 2 ).run();
        }, "LOL", 2000 * 1024 * 1024 ).run();
    }



    void TLE(){ for(;;); }

    void MLE(){
        int[][] adj = new int[1024*1024][];
        for( int i = 0; i < adj.length; ++i )
            adj[i] = new int[1024*1024];
    }

    void exit( int val ){
        out.flush();
        System.exit(val);
    }
    //////////////////////////////////////////////////////////////////////////////////////////

    class Seg implements Comparable<Seg>{
        int jl, jr;
        Seg( int _jl, int _jr ){
            jl = _jl;
            jr = _jr;
        }
        public int compareTo(Seg b) {
            int val = Integer.compare(jl, b.jl);
//            if( val == 0 )
//                return Integer.compare(jr, b.jr);
            return val;
        }
        public String toString(){
            return String.format( "(%d, %d)", jl, jr );
        }
    }

    int n, m;
    TreeMap<Integer,TreeSet<Integer>> pt = new TreeMap<>();

    void solve(){
        n = sc.nextInt();
        m = sc.nextInt();
        for( int it = 0; it < m; ++it ){
            int i = sc.nextInt();
            int j = sc.nextInt();
            if( !pt.containsKey(i) )
                pt.put( i, new TreeSet<Integer>() );
            pt.get(i).add( j );
            if( i==n && j==n ){
                out.println("-1");
                return;
            }
        }

        TreeSet<Seg> ts = new TreeSet<>();
        if( pt.containsKey(1) )
            ts.add( new Seg(1,pt.get(1).first()-1) );
        else
            ts.add( new Seg(1,n) );

        for( int i : pt.keySet() ){
            if( i!=1 && !pt.containsKey(i-1) ){
                int jl = ts.first().jl;
                ts.clear();
                ts.add(new Seg(jl,n));
            }

            for( int j : pt.get(i) ){
                Seg s = ts.floor(new Seg(j,n+1));
                if( s!=null && s.jl <= j && j <= s.jr ){
                    ts.remove(s);
                    if( s.jl <= j-1 )
                        ts.add(new Seg(s.jl, j-1));
                    if( j+1 <= s.jr )
                        ts.add(new Seg(j+1, s.jr));
                }
                if( s!=null && s.jr <= j ){
                    Integer j0 = pt.get(i).lower(j);
                    if( j0 == null || j0 < s.jl ){
                        s.jr = j-1;
                    }
                }
            }
            if( ts.isEmpty() ){
                out.println("-1");
                return;
            }

            if( pt.containsKey(i-1) )
                for( int j : pt.get(i-1) ){
                    Seg a = ts.lower (new Seg(j,j));
                    Seg b = ts.higher(new Seg(j,j));
                    if( a==null || b==null ) continue;
                    Integer midP = pt.get(i).lower(b.jl);
                    if( midP==null || midP<a.jr ){
                        ts.remove(b);
                        ts.remove(a);
                        a.jr = b.jr;
                        ts.add(a);
                    }
                }

            {
                int jLast = pt.get(i).last();
                int jl = -1;
                while( !ts.isEmpty() && jLast < ts.last().jl ){
                    jl = ts.last().jl;
                    ts.pollLast();
                }
                if( jl != -1 ) ts.add( new Seg(jl,n) );
            }
            int adada = 13;
        }
        if( !pt.containsKey(n) ){
            int jl = ts.first().jl;
            ts.clear();
            ts.add(new Seg(jl,n));
        }

        if( ts.last().jr == n )
            out.println( 2*(n-1) );
        else
            out.println("-1");
    }









}