#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 * 2000;
pair<int, int> a[MAXN];
set<pair<int, int> > seq;
void relax() {
  for (auto it = seq.begin(); it != seq.end();) {
    if (it != seq.begin()) {
      auto la = it;
      la--;
      if (la->second + 1 == it->first) {
        pair<int, int> ans = make_pair(la->first, it->second);
        seq.erase(it);
        seq.erase(la);
        seq.insert(ans);
        it = seq.upper_bound(ans);
      } else
        it++;
    } else
      it++;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> a[i].first >> a[i].second;
  sort(a, a + m);
  int ind = 0;
  while (ind < m && a[ind].first == 1) ind++;
  if (ind > 0) seq.insert(make_pair(a[0].second, n));
  for (int i = 2; i <= n;) {
    set<pair<int, int> > _new;
    vector<int> curp;
    while (ind < m && a[ind].first == i) curp.push_back(a[ind].second), ind++;
    int indp = 0;
    auto it = seq.begin();
    if (it->first == 1) {
      _new.insert(*it);
      while (indp < (int)curp.size() && curp[indp] <= it->second) indp++;
      it++;
    }
    for (; it != seq.end(); it++) {
      while (indp < (int)curp.size() && curp[indp] < it->first - 1)
        _new.insert(make_pair(curp[indp], curp[indp])), indp++;
      if (indp < (int)curp.size() && curp[indp] <= it->second) {
        _new.insert(make_pair(curp[indp], it->second));
        while (indp < (int)curp.size() && curp[indp] <= it->second) indp++;
      }
    }
    while (indp < (int)curp.size()) {
      _new.insert(make_pair(curp[indp], curp[indp]));
      indp++;
    }
    seq = _new;
    relax();
    if (curp.empty() && ind == m) break;
    if (curp.empty() && ind < m)
      i = a[ind].first;
    else
      i++;
  }
  if (seq.empty())
    cout << 2 * n - 2;
  else {
    auto en = seq.end();
    en--;
    if (en->second == n)
      cout << -1;
    else
      cout << 2 * n - 2;
  }
  return 0;
}
