#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> pair) {
  out << "(" << pair.first << ", " << pair.second << ")";
  return out;
}
map<int, vector<int> > volc;
int n, m;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  int x, y;
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < (m); ++i) {
    cin >> x >> y;
    volc[x].push_back(y);
  }
  for (__typeof((volc).begin()) it = ((volc).begin()); it != (volc).end();
       ++it) {
    (it->second).push_back(0);
    (it->second).push_back(n + 1);
    sort(it->second.begin(), it->second.end());
  }
  set<pair<int, int> > acc;
  acc.insert(make_pair(1, 1));
  int last = 0;
  set<pair<int, int> > tmp;
  for (__typeof((volc).begin()) it = ((volc).begin()); it != (volc).end();
       ++it) {
    if (acc.empty()) {
      break;
    }
    acc.insert(make_pair(n + 2, n + 2));
    int lev = it->first;
    __typeof(acc.begin()) a = (acc.begin());
    tmp.clear();
    if (lev == last + 1) {
      for (int y = 1; y <= ((int)(it->second).size() - 1); ++y) {
        int vol2 = (it->second)[y] - 1;
        int vol1 = (it->second)[y - 1] + 1;
        if (vol1 > vol2) continue;
        while (a->second < vol1) {
          a++;
        }
        if (a->first > vol2) continue;
        tmp.insert(make_pair(max(vol1, a->first), vol2));
      }
    } else {
      int sta = acc.begin()->first;
      for (int y = 1; y <= ((int)(it->second).size() - 1); ++y) {
        int vol2 = (it->second)[y] - 1;
        int vol1 = (it->second)[y - 1] + 1;
        if (vol1 > vol2) continue;
        if (sta > vol2) continue;
        tmp.insert(make_pair(max(vol1, sta), vol2));
      }
    }
    acc = tmp;
    last = lev;
  }
  bool suresucc = false;
  for (__typeof((acc).begin()) it = ((acc).begin()); it != (acc).end(); ++it) {
    if (it->first <= n && n <= it->second) {
      suresucc = true;
    }
  }
  if (last != n) suresucc = true;
  if (!acc.empty() && suresucc) {
    cout << 2ll * (long long)n - 2 << endl;
  } else {
    cout << -1 << endl;
  }
}
