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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class  D{
	
	static class Scanner{
		BufferedReader br=null;
		StringTokenizer tk=null;
		public Scanner(){
			br=new BufferedReader(new InputStreamReader(System.in));
		}
		public String next() throws IOException{
			while(tk==null || !tk.hasMoreTokens())
				tk=new StringTokenizer(br.readLine());
			return tk.nextToken();
		}
		public int nextInt() throws NumberFormatException, IOException{
			return Integer.valueOf(next());
		}
		public long nextLong() throws NumberFormatException, IOException{
			return Long.valueOf(next());
		}
		public double nextDouble() throws NumberFormatException, IOException{
			return Double.valueOf(next());
		}
	}
	
	
	static class Intervalo implements Comparable<Intervalo>{
		int a, b;
		public Intervalo(int aa, int bb){
			a = aa;
			b = bb;
		}
		@Override
		public int compareTo(Intervalo o) {
			return b - o.b;
		}
		public String toString(){
			return String.format("(%d, %d)", a, b);
		}
	}
	
	static int N, M;
	
	
	static LinkedList<Intervalo> get_intervalos(ArrayList<Integer> list){
		int a = 0;
		list.add(N);
		Collections.sort(list);
		LinkedList<Intervalo> ret = new LinkedList<Intervalo>();
		for(int e: list){
			int b = e - 1;
			if (b < a){
				a = e + 1;
				continue;
			}
			ret.add(new Intervalo(a, b));
			a = e + 1;
		}
		return ret;
	}
	
	static TreeSet<Intervalo> update(LinkedList<Intervalo> list, TreeSet<Intervalo> anterior){
		TreeSet<Intervalo> ret = new TreeSet<Intervalo>();
		if (anterior.size() == 0 || list.size() == 0)
			return ret;
		for(Intervalo inter: list){
			Intervalo consulta = new Intervalo(inter.a, inter.a);
			Intervalo mejoranterior = anterior.ceiling(consulta);
			if (mejoranterior == null)
				continue;
			if (mejoranterior.a > inter.b)
				continue;
			if (mejoranterior.a < inter.a)
				ret.add(inter);
			else
				ret.add(new Intervalo(mejoranterior.a, inter.b));
		}
		return ret;
	}
	
	
	public static void main(String args[]) throws NumberFormatException, IOException{
		Scanner sc = new Scanner();
		N = sc.nextInt();
		M = sc.nextInt();
		HashMap<Integer, ArrayList<Integer>> map = new HashMap<Integer, ArrayList<Integer>>();
		HashSet<Integer> copy = new HashSet<Integer>();
		for(int i = 0; i < M; i++){
			int x = sc.nextInt();
			int y = sc.nextInt();
			x--;y--;
			copy.add(x);
			if (map.containsKey(x))
				map.get(x).add(y);
			else{
				ArrayList<Integer> t = new ArrayList<Integer>();
				t.add(y);
				map.put(x, t);
			}
		}
		
		for(int x: copy)
			if (x < N - 1 && !map.containsKey(x + 1))
				map.put(x + 1, new ArrayList<Integer>());
		if (!map.containsKey(0))
			map.put(0, new ArrayList<Integer>());
		if (!map.containsKey(N - 1))
			map.put(N - 1, new ArrayList<Integer>());
		TreeSet<Intervalo> ant = new TreeSet<Intervalo>();
		ant.add(new Intervalo(0, 0));
		
		int[] tmp = new int[map.size()];
		int index = 0;
		for(int k: map.keySet())
			tmp[index++] = k;
		Arrays.sort(tmp);
		
		
		for(int i = 0; i < index; i++){
			int current = tmp[i];
			LinkedList<Intervalo> list = get_intervalos(map.get(current));
			ant = update(list, ant);
		}
		
		Intervalo ultimo = null;
		if (ant.size() > 0)
			ultimo = ant.last();
		if (ultimo == null || (ultimo.b != N - 1))
			System.out.println("-1");
		else
			System.out.println(2*N - 2);
		
		
	}

}
