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 B {
	class Segment implements Comparable<Segment> {
		int diag;
		int from, to, len;
		boolean left, right;
		
		public Segment(int diag, int from, int to) {
			this.diag = diag;
			this.from = from;
			this.to = to;
			len = to - from;
			left = (from == 0);
			right = (to == diag + 1);
		}

		@Override
		public int compareTo(Segment that) {
			return from - that.from;
		}
		
		boolean update(int newDiag) {
			int delta = newDiag - diag;
			if (!left) {
				from += delta;
			}
			if (right) {
				to += delta;
			}
			len = to - from;
			diag = newDiag;
			return len > 0;
		}
		
		@Override
		public String toString() {
			return diag + " " + from + "-" + to;
		}
	}
	
	int n;
	
	void run() {
		n = in.nextInt();
		int m = in.nextInt();
		Segment[] segments = new Segment[m];
		for (int i = 0; i < m; i++) {
			int x = in.nextInt() - 1;
			int y = in.nextInt() - 1;
			segments[i] = new Segment(x + y, x, x + 1);
		}
		Arrays.sort(segments, new Comparator<Segment>() {
			@Override
			public int compare(Segment a, Segment b) {
				int res = a.diag - b.diag;
				if (res != 0) {
					return res;
				}
				return a.from - b.from;
			}
		});
		TreeSet<Segment> set = new TreeSet<Segment>();
		for (Segment segment : segments) {
			int diag = segment.diag;
			Segment prev = set.floor(segment);
			if(prev != null) {
				if (!prev.update(diag)) {
					set.remove(prev);
					prev = null;
				}
			}
			if (prev != null) {
				if (prev.from <= segment.from && segment.to <= prev.to) {
					continue;
				}
				if (segment.from == prev.to) {
					set.remove(prev);
					segment = new Segment(diag, prev.from, segment.to);
					set.add(segment);
				} else {
					set.add(segment);
				}
			} else {
				set.add(segment);
			}
			Segment next = set.higher(segment);
			if(next != null) {
				if (!next.update(diag)) {
					set.remove(next);
					next = null;
				}
			}
			if (next != null) {
				if (segment.to == next.from) {
					set.remove(segment);
					set.remove(next);
					segment = new Segment(diag, segment.from, next.to);
					set.add(segment);
				}
			}
		}
		Segment finish = new Segment(2 * n - 2, n - 1, n);
		Segment prev = set.floor(finish);
		if(prev != null) {
			if (!prev.update(finish.diag)) {
				set.remove(prev);
				prev = null;
			}
		}
		if (prev != null) {
			if (prev.from <= finish.from && finish.to <= prev.to) {
				out.println(-1);
				return;
			}
		}
		out.println(finish.diag);
	}

	static boolean stdStreams = true;
	static String fileName = B.class.getSimpleName().replaceFirst("_.*", "").toLowerCase();
	static String inputFileName = fileName + ".in";
	static String outputFileName = fileName + ".out";
	static MyScanner in;
	static PrintWriter out;

	public static void main(String[] args) throws IOException {
		Locale.setDefault(Locale.US);
		BufferedReader br;
		if (stdStreams) {
			br = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
		} else {
			br = new BufferedReader(new FileReader(inputFileName));
			out = new PrintWriter(outputFileName);
		}
		in = new MyScanner(br);
		new B().run();
		br.close();
		out.close();
	}
	
	static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		MyScanner(BufferedReader br) {
			this.br = br;
		}
		
		void findToken() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
		}
		
		String next() {
			findToken();
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
		
		double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}
