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;
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
long long comb(long long n, long long r) {
  if (r < 0 || r > n) return 0;
  if ((n - r) < r) r = n - r;
  long long vec = 1;
  for (long long i = n; i > n - r; --i) {
    vec = vec * i;
  }
  for (long long i = 1; i < r + 1; ++i) {
    vec = vec / i;
  }
  return vec;
}
template <typename T>
void press(T &v) {
  v.erase(unique(v.begin(), v.end()), v.end());
}
long long small(vector<long long> &vec, long long first) {
  return lower_bound(vec.begin(), vec.end(), first) - vec.begin();
}
long long osmall(vector<long long> &vec, long long first) {
  return upper_bound(vec.begin(), vec.end(), first) - vec.begin();
}
long long big(vector<long long> &vec, long long first) {
  return vec.size() - osmall(vec, first);
}
long long obig(vector<long long> &vec, long long first) {
  return vec.size() - small(vec, first);
}
long long freq(vector<long long> &vec, long long first) {
  return upper_bound(vec.begin(), vec.end(), first) -
         lower_bound(vec.begin(), vec.end(), first);
}
long long maxa(vector<long long> &vec) {
  return max_element(vec.begin(), vec.end()) - vec.begin();
}
long long mina(vector<long long> &vec) {
  return min_element(vec.begin(), vec.end()) - vec.begin();
}
long long Set(long long qq, long long pos) { return (qq | (1 << pos)); }
long long chk(long long qq, long long pos) { return (qq & (1 << pos)); }
long long bits(long long qq) { return __builtin_popcount(qq); }
long long p2[32];
long long modpow(long long first, long long n, long long m) {
  if (n == 0) return 1 % m;
  long long u = modpow(first, n / 2, m);
  u = (u * u) % m;
  if (n % 2 == 1) u = (u * first) % m;
  return u;
}
long long _pow(long long vec, long long b) {
  if (!b) return 1;
  long long temp = _pow(vec, b / 2);
  temp = (temp * temp);
  if (b % 2) return (vec * temp);
  return temp;
}
long long cl(long long vec, long long b) {
  if (vec % b) return 1 + vec / b;
  return vec / b;
}
long long dx[] = {0, 0, -1, 1, 1, 1, -1, -1};
long long dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
const long long MOD = 1e9 + 7;
const long long inf = 1e18;
const long long N = 1e6 + 5;
const long long K = 1e3 + 10;
vector<pair<long long, long long> > rs, rs2;
pair<long long, long long> w[N];
vector<long long> second;
long long n, m;
void solve() {
  cin >> n >> m;
  for (long long i = 0; i < m; i++) cin >> w[i].first >> w[i].second;
  sort(w, w + m);
  long long first = 1, lastx = 0, ind = 0, mn = 1;
  rs.push_back(make_pair(1, w[0].second - 1));
  for (long long j = 0; j < m; j++) {
    second.clear();
    rs2.clear();
    first = w[j].first;
    if (first != lastx + 1) {
      rs.clear();
      rs.push_back(make_pair(mn, n));
    }
    lastx = first;
    for (; j < m && w[j].first == first; j++) second.push_back(w[j].second);
    j--;
    second.push_back(n + 1);
    ind = 0;
    for (long long i = 0; i < rs.size(); i++) {
      bool fl = 0;
      while (second.size() > ind && second[ind] < rs[i].first) ind++, fl = 1;
      while (second.size() > ind && second[ind] <= rs[i].second) {
        rs2.push_back(make_pair(rs[i].first, second[ind] - 1));
        rs[i].first = second[ind] + 1;
        ind++;
        fl = 1;
      }
      if (!fl) rs2.push_back(make_pair(rs[i].first, second[ind] - 1));
      if (fl && second[ind - 1] < rs[i].second)
        rs2.push_back(make_pair(rs[i].first, second[ind] - 1));
      rs2.push_back(rs[i]);
    }
    if (second[second.size() - 2] < rs.back().second)
      rs2.push_back(make_pair(second[second.size() - 2] + 1, n));
    rs.clear();
    sort(rs2.begin(), rs2.end());
    for (long long k = 1; k < rs2.size(); k++)
      if (rs2[k - 1].second >= rs2[k].first) {
        rs2[k].first = rs2[k - 1].first;
        rs2[k - 1].second = -1;
      }
    for (long long k = 0; k < rs2.size(); k++)
      if (rs2[k].first <= rs2[k].second) rs.push_back(rs2[k]);
    if (rs.empty() || (first == n && rs.size() && rs.back().second != n)) {
      cout << -1 << endl;
      return;
    }
    mn = max(mn, rs[0].first);
  }
  cout << 2 * n - 2 << endl;
}
signed main() {
  for (long long i = 0; i < 32; i++) p2[i] = (1 << i);
  cout << fixed << setprecision(12);
  long long t;
  t = 1;
  for (long long i = 1; i <= t; i++) {
    solve();
  }
}
