#include <bits/stdc++.h>
using namespace std;
long n, m, a, b;
vector<pair<long, long> > v;
long clev, plev, cl[200000], cr[200000], pl[200000], pr[200000];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> a >> b;
    v.push_back(make_pair(a, b));
  }
  sort(v.begin(), v.end());
  clev = 0;
  plev = 1;
  pl[0] = pr[0] = 1;
  long i = 0;
  while (true) {
    if (i == m) break;
    clev = 0;
    if ((i == 0 && v[i].first > 1) ||
        (i > 0 && v[i].first != v[i - 1].first + 1))
      plev = 1, pr[0] = n;
    long r = i;
    while (r < m && v[r].first == v[i].first) ++r;
    --r;
    long lp = 1;
    for (int k = i; k <= r; k++) {
      if (v[k].second > lp) {
        cl[clev] = lp;
        cr[clev] = v[k].second - 1;
        ++clev;
      }
      lp = v[k].second + 1;
    }
    if (lp <= n) {
      cl[clev] = lp;
      cr[clev] = n;
      ++clev;
    }
    lp = 0;
    for (int k = 0; k < clev; k++) {
      while (lp < plev && pr[lp] < cl[k]) ++lp;
      if (lp == plev || pl[lp] > cr[k])
        cr[k] = cl[k] = 2e9 + 5;
      else
        cl[k] = max(cl[k], pl[lp]);
    }
    plev = 0;
    for (int k = 0; k < clev; k++) {
      if (cl[k] < 2e9) {
        pl[plev] = cl[k];
        pr[plev] = cr[k];
        ++plev;
      }
    }
    if (plev == 0) {
      cout << -1 << endl;
      return 0;
    }
    i = r + 1;
  }
  if (v[m - 1].first != n) {
    plev = 1;
    pr[0] = n;
  }
  if (pr[plev - 1] == n)
    cout << 2 * n - 2 << endl;
  else
    cout << -1 << endl;
  cin.get();
  cin.get();
  return 0;
}
