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.io.*;
import java.util.*;

public class CF {

	class V implements Comparable<V>{
		int x, y;

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

		@Override
		public int compareTo(V o) {
			if (x == o.x)
				return Integer.compare(y, o.y);
			return Integer.compare(x, o.x);
		}
	}
	
	class Seg {
		int fr, to;
		
		Seg(int fr, int to) {
			this.fr = fr;
			this.to = to;
		}

		@Override
		public String toString() {
			return "Seg [fr=" + fr + ", to=" + to + "]";
		}
		
		
	}

	void solve() {
		int n = in.nextInt();
		int m = in.nextInt();
		V[] a = new V[m];
		for (int i = 0; i < m; i++) {
			a[i] = new V(in.nextInt(), in.nextInt());
		}
		Arrays.sort(a);
		ArrayList<Seg> can = new ArrayList<>();
		can.add(new Seg(1, 1));
		int iter = 0;
		int lastX = 0;
		while (true) {
			if (can.size() == 0) {
				out.println(-1);
				return;
			}
			int nextX = lastX + 1;
			if (nextX == n + 1) {
				if (can.get(can.size() - 1).to == n) {
					out.println(n * 2 - 2);
				} else {
					out.println(-1);
				}
				return;
			}
			ArrayList<Integer> nowFail = new ArrayList<>();
			nowFail.add(0);
			while (iter < m && a[iter].x == nextX) {
				nowFail.add(a[iter].y);
				iter++;
			}
			nowFail.add(n + 1);
			if (nowFail.size() == 2) {
				int from = can.get(0).fr;
				can.clear();
				can.add(new Seg(from, n));
				lastX = (iter < m ? a[iter].x - 1 : n);
			} else {
				int nowIter = 0;
				ArrayList<Seg> newCan = new ArrayList<>();
				for (int i = 0; i < nowFail.size() - 1; i++) {
					int okFrom = nowFail.get(i) + 1;
					int okTo = nowFail.get(i + 1) - 1;
					while (nowIter != can.size() && can.get(nowIter).to < okFrom)
						nowIter++;
					if (nowIter != can.size()) {
						okFrom = Math.max(okFrom, can.get(nowIter).fr);
					} else {
						okTo = -1;
					}
					if (okTo < okFrom)
						continue;
					newCan.add(new Seg(okFrom, okTo));
				}
				can = newCan;
				lastX = nextX;
			}
		}
	}

	FastScaner in;
	PrintWriter out;

	void run() {
		in = new FastScaner(System.in);
		out = new PrintWriter(System.out);

		solve();

		out.close();
	}

	void runWithFiles() {
		in = new FastScaner(new File("input.txt"));
		try {
			out = new PrintWriter(new File("output.txt"));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}

		solve();

		out.close();
	}

	public static void main(String[] args) {
		Locale.setDefault(Locale.US);
		new CF().run();
	}

	class FastScaner {
		BufferedReader br;
		StringTokenizer st;

		FastScaner(InputStream is) {
			br = new BufferedReader(new InputStreamReader(is));
		}

		FastScaner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return null;
				st = new StringTokenizer(s);
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}