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.awt.Point;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.Comparator;
import java.util.InputMismatchException;
import java.util.LinkedList;

public class D {
    public static void merge(Point[] B, int cnt1, Point[] N, int cnt2) {
        for (int i = 0; i < cnt2; i++) {
            int lo = 0;
            int hi = cnt1 - 1;
            int ans = -1;
            while (lo <= hi) {
                int mid = (lo + hi) / 2;
                if (B[mid].y >= N[i].x) {
                    ans = mid;
                    hi = mid - 1;
                } else
                    lo = mid + 1;
            }
            if (ans == -1 || N[i].y < B[ans].x)
                N[i].x = -1;
            else {
                int inter = Math.max(N[i].x, B[ans].x);
                N[i].x = inter;
            }
        }
    }

    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        int n = in.readInt();
        int m = in.readInt();
        LinkedList<Point> V = new LinkedList<Point>();
        for (int i = 0; i < m; i++)
            V.add(new Point(in.readInt(), in.readInt()));
        Collections.sort(V, new Comparator<Point>() {
            public int compare(Point o1, Point o2) {
                if (o1.x != o2.x)
                    return o1.x - o2.x;
                return o1.y - o2.y;
            }
        });
        Point[] B = new Point[m + 1];
        Point[] N = new Point[m + 1];
        B[0] = new Point(1, n);
        int cnt = 1;
        while (!V.isEmpty()) {
            int row = V.getFirst().x;
            int index = 0;
            int st = 1;
            while (!V.isEmpty() && V.getFirst().x == row) {
                int col = V.remove().y;
                if (col != st)
                    N[index++] = new Point(st, col - 1);
                st = col + 1;
            }
            if (st <= n)
                N[index++] = new Point(st, n);
            if (row == 1)
                index = 1;
            else
                merge(B, cnt, N, index);
            cnt = 0;
            for (int i = 0; i < index; i++)
                if (N[i].x != -1)
                    B[cnt++] = N[i];
            if (cnt == 0) {
                B[cnt++] = new Point(-1, -1);
                break;
            }
            if ((V.isEmpty() && row != n)
                    || (!V.isEmpty() && V.getFirst().x != row + 1)) {
                int min = Integer.MAX_VALUE;
                for (int i = 0; i < cnt; i++)
                    min = Math.min(B[i].x, min);
                cnt = 0;
                B[cnt++] = new Point(min, n);
            }
        }
        boolean can = false;
        for (int i = 0; i < cnt; i++)
            can |= B[i].x <= n && B[i].y >= n;
        if (can)
            System.out.println(2 * n - 2);
        else
            System.out.println(-1);
    }
}

class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1000];
    private int curChar, numChars;

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

    private 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 readInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public long readLong() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        long res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public String readString() {
        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;
    }

    private String readLine0() {
        StringBuffer buf = new StringBuffer();
        int c = read();
        while (c != '\n' && c != -1) {
            buf.appendCodePoint(c);
            c = read();
        }
        return buf.toString();
    }

    public String readLine() {
        String s = readLine0();
        while (s.trim().length() == 0)
            s = readLine0();
        return s;
    }

    public String readLine(boolean ignoreEmptyLines) {
        if (ignoreEmptyLines)
            return readLine();
        else
            return readLine0();
    }

    public char readCharacter() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        return (char) c;
    }

    public double readDouble() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        double res = 0;
        while (!isSpaceChar(c) && c != '.') {
            if (c == 'e' || c == 'E')
                return res * Math.pow(10, readInt());
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        }
        if (c == '.') {
            c = read();
            double m = 1;
            while (!isSpaceChar(c)) {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, readInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                m /= 10;
                res += (c - '0') * m;
                c = read();
            }
        }
        return res * sgn;
    }
}