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

public class Volcanoes {
	
	static PrintWriter out;
	static InputReader in;
	static int N;
	static int M;
	public static void main(String[] args) throws Exception {
		in = new InputReader(System.in);
		out = new PrintWriter(System.out);
		
		N = in.nextInt();
		M = in.nextInt();
		
		Map<Integer, List<Integer>> blocks = new TreeMap<Integer, List<Integer>>();
		for(int i=0;i<M;i++) {
			int r = in.nextInt();
			int c = in.nextInt();
			put(blocks, r, c);
		}
		
		int prevLayer = -1000;
		Set<Integer> layers = new TreeSet<Integer>();
		layers.addAll(blocks.keySet());
		// add N+1 separators for easier code
		for(int layer : layers) {
			put(blocks, layer, N+1);
			if(prevLayer > 0) {
				// only keep track of 1 empty row for consecutive ones
				if(prevLayer + 1 != layer) {
					put(blocks, prevLayer+1, N+1);
				}
			}
			prevLayer = layer;
		}
		
		if(!blocks.containsKey(1)) {
			put(blocks, 1, N+1);
		}
		if(!blocks.containsKey(N)) {
			put(blocks, N, N+1);
		}
		
		boolean good = true;
		TreeSet<Interval> intervals = new TreeSet<Interval>(new Comparator<Interval>() {
			@Override
			public int compare(Interval o1, Interval o2) {
				int dl = o1.l - o2.l;
				if(dl != 0) {
					return dl;
				}
				return o1.r - o2.r;
			}
		});
		intervals.add(new Interval(1,  1));
		Interval[] toRemove = new Interval[2*M+5];
		int sz = 0;
		for(int row : blocks.keySet()) {
			List<Integer> layer = blocks.get(row);
			Collections.sort(layer);
			int prevBlock = 0;
			for(int block : layer) {
				Interval left = intervals.ceiling(new Interval(prevBlock+1, prevBlock+1));
				if(left == null) {
					break;
				}
				if(left.l > block) {
					continue;
				}
				int leftmost = left.l;
				sz = 0;
				Interval toAdd = null;
				for(Interval interval : intervals.tailSet(left)) {
					if(interval.l <= block)
						toRemove[sz++] = interval;
					if(interval.r >= block) {
						if(interval.l <= block) {
							if(block+1 <= interval.r)
								toAdd = new Interval(block+1, interval.r);
						}
						break;
					}
				}
				for(int i=0;i<sz;i++){
					intervals.remove(toRemove[i]);
				}
				if(toAdd != null)
					intervals.add(toAdd);
				
				if(block-1 >= leftmost) {
					intervals.add(new Interval(leftmost, block-1));
				}
				prevBlock = block;
			}
			if(intervals.size() == 0) {
				good = false;
				break;
			}
			/*
			System.out.println("layer = " + row);
			System.out.println("blocks = " + blocks.get(row));
			System.out.println(intervals);*/
		}
		if(good)
			good = intervals.last().r == N;
		if(good) {
			out.println(2*N-2);
		}else{
			out.println(-1);
		}
		
		out.close();
	}
	
	static void put(Map<Integer, List<Integer>> map, int key, int val) {
		if(!map.containsKey(key)){
			map.put(key, new ArrayList());
		}
		map.get(key).add(val);
	}
	
	static class Interval {
		public int l;
		public int r;
		public Interval(int l, int r) {
			this.l = l;
			this.r = r;
		}
		@Override
		public String toString() {
			return "[l=" + l + ", r=" + r + "]";
		}
	}
	
	static class InputReader {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;

		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() {
			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 nextLong() {
			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 nextToken() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return isWhitespace(c);
		}

		public static boolean isWhitespace(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
	}
}
