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 java.util.List;
import java.io.IOException;
import java.util.InputMismatchException;
import java.util.TreeMap;
import java.util.ArrayList;
import java.util.Set;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Collections;
import java.util.Collection;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author George Marcus
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskB {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int N = in.nextInt();
        int M = in.nextInt();
        Pair[] P = new Pair[M];
        TreeMap<Integer, Integer> lines = new TreeMap<Integer, Integer>();
        for(int i = 0; i < M; i++) {
            P[i] = new Pair(in.nextInt(), in.nextInt());
            lines.put(P[i].x, 0);
            if(P[i].x + 1 <= N)
                lines.put(P[i].x + 1, 0);
        }

        int numLines = lines.size();
        ArrayList<Integer>[] obstacles = new ArrayList[numLines];
        for(int i = 0; i < numLines; i++)
            obstacles[i] = new ArrayList<Integer>();

        int idx = 0;
        for(int x : lines.keySet()) {
            lines.put(x, idx);
            idx++;
        }

        for(int i = 0; i < M; i++) {
            int line = lines.get(P[i].x);
            obstacles[line].add(P[i].y);
        }

        ArrayList<Pair> last = new ArrayList<Pair>();
        ArrayList<Pair> next = new ArrayList<Pair>();
        ArrayList<Pair> cand = new ArrayList<Pair>();
        if(lines.containsKey(1)) {
            int first = obstacles[0].get(0);
            last.add(new Pair(1, first - 1));
        }
        else
            last.add(new Pair(1, N));
        for(int i = 0; i < numLines; i++) {
            cand.clear();
            next.clear();
            obstacles[i].add(0);
            obstacles[i].add(N + 1);
            Collections.sort(obstacles[i]);

            for(int j = 1; j < obstacles[i].size(); j++) {
                int a = obstacles[i].get(j - 1) + 1;
                int b = obstacles[i].get(j) - 1;
                if(a <= b)
                    cand.add(new Pair(a, b));
            }

            if(cand.size() > 0) {
                for(Pair p : cand) {
                    int pos = Collections.binarySearch(last, new Pair(-1, p.x));
                    if(pos < 0)
                        pos = -pos - 1;
                    if(pos == last.size())
                        pos = last.size() - 1;

                    int px = last.get(pos).x;
                    int py = last.get(pos).y;
                    if(py >= p.x && px <= p.y)
                        next.add(new Pair(Math.max(p.x, px), p.y));
                }
            }

            last.clear();
            last.addAll(next);
            if(last.size() == 0)
                break;
        }

        if(last.size() > 0 && last.get(last.size() - 1).y == N)
            out.println(2 * N - 2);
        else
            out.println(-1);
    }

    private class Pair implements Comparable<Pair> {
        public int x;
        public int y;

        private Pair(int x, int y) {
            this.x = x;
            this.y = y;
        }

        public int compareTo(Pair o) {
            if(y != o.y)
                return y - o.y;
            return x - o.x;
        }
    }
}

class InputReader {
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int nextInt() {
        return Integer.parseInt(nextString());
    }

    public String nextString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuffer res = new StringBuffer();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));

        return res.toString();
    }

    private boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    }

