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).
#include <bits/stdc++.h>
using namespace std;
const int maxm = 100004;
int n, m, mx[maxm];
pair<int, int> a[maxm], b[maxm], p[maxm];
int an, bn;
int Find1(int x, int y) {
  int l(1), r(an), mid;
  while (l < r) {
    mid = (l + r) >> 1;
    if (a[mid].second >= x)
      r = mid;
    else
      l = mid + 1;
  }
  if (x > a[l].second || y < a[l].first) return 0;
  return l;
}
int Find2(int x, int y) {
  int l(1), r(an), mid;
  while (l < r) {
    mid = (l + r) >> 1;
    if (a[mid + 1].first <= y)
      l = mid + 1;
    else
      r = mid;
  }
  if (x > a[l].second || y < a[l].first) return 0;
  return l;
}
int main() {
  int i, j, k, t, ii, jj, kk, tt;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= m; i++) scanf("%d%d", &p[i].first, &p[i].second);
  sort(p + 1, p + m + 1);
  a[an = 1] = pair<int, int>(1, 1);
  int x(0);
  for (i = 1; i <= m;) {
    if (p[i].first > x + 1) a[an = 1] = pair<int, int>(a[1].first, n);
    for (j = i; p[j].first == p[i].first; i++)
      ;
    x = p[j].first;
    bn = 0;
    for (t = 0, k = j; k < i; t = p[k++].second)
      if (t + 1 <= p[k].second - 1)
        b[++bn] = pair<int, int>(t + 1, p[k].second - 1);
    if (t + 1 <= n) b[++bn] = pair<int, int>(t + 1, n);
    if (!bn) {
      puts("-1");
      return 0;
    }
    for (k = 1; k <= bn; k++) {
      ii = Find1(b[k].first, b[k].second);
      jj = Find2(b[k].first, b[k].second);
      mx[k] = int(~0U >> 1);
      if (ii) mx[k] = min(mx[k], max(a[ii].first, b[k].first));
      if (jj) mx[k] = min(mx[k], max(a[jj].first, b[k].first));
    }
    an = 0;
    for (k = 1; k <= bn; k++)
      if (mx[k] < int(~0U >> 1)) a[++an] = pair<int, int>(mx[k], b[k].second);
    if (!an) {
      puts("-1");
      return 0;
    }
  }
  if (x < n) a[an = 1] = pair<int, int>(a[1].first, n);
  if (!an || a[an].second < n) {
    puts("-1");
    return 0;
  }
  printf("%d\n", 2 * (n - 1));
  return 0;
}
