#include <bits/stdc++.h>
using namespace std;
inline int ni() {
  int a;
  scanf("%d", &a);
  return a;
}
inline double nf() {
  double a;
  scanf("%lf", &a);
  return a;
}
template <class T>
void out(T a, T b) {
  bool first = true;
  for (T i = a; i != b; i++) {
    if (!first) printf(" ");
    first = false;
    cout << *i;
  }
  puts("");
}
template <class T>
void outl(T a, T b) {
  for (T i = a; i != b; i++) cout << *i << "\n";
}
int n, m;
vector<pair<int, int> > v;
map<int, vector<int> > p;
set<pair<int, int> > s;
vector<pair<int, int> > cur;
vector<pair<int, int> > w;
int mx;
int main() {
  n = ni();
  m = ni();
  v.resize(m);
  for (int i = 0; i < (int)(m); i++) {
    v[i].first = ni();
    v[i].second = ni();
    p[v[i].first].push_back(v[i].second);
    mx = max(mx, v[i].first);
  }
  for (map<int, vector<int> >::iterator it = p.begin(); it != p.end(); it++)
    sort((it->second).begin(), (it->second).end());
  s.insert(make_pair(1, 1));
  int last = 0;
  for (map<int, vector<int> >::iterator it = p.begin(); it != p.end();) {
    if (s.empty()) break;
    cur.clear();
    if (last + 1 < it->first) {
      cur.push_back(make_pair(1, n));
      last = it->first - 1;
    } else {
      int f = 1, lst = n;
      for (int i = 0; i < (int)(((int)(it->second).size())); i++) {
        if (f < it->second[i]) {
          cur.push_back(make_pair(f, it->second[i] - 1));
        }
        f = it->second[i] + 1;
      }
      if (f <= lst) cur.push_back(make_pair(f, lst));
      last = it->first;
      it++;
    }
    int d = 0;
    w.clear();
    for (set<pair<int, int> >::iterator sit = s.begin();
         sit != s.end() && d < ((int)(cur).size());) {
      while (d < ((int)(cur).size()) && cur[d].second < sit->first) d++;
      if (d < ((int)(cur).size()) && cur[d].first <= sit->second) {
        w.push_back(make_pair(max(cur[d].first, sit->first), cur[d].second));
        d++;
      } else {
        sit++;
      }
    }
    s.clear();
    for (int i = 0; i < (int)(((int)(w).size())); i++) s.insert(w[i]);
  }
  if (!s.empty()) {
    if (last == n) {
      if (s.rbegin()->second == n)
        cout << 2 * (n - 1) << endl;
      else
        puts("-1");
    } else {
      cout << 2 * (n - 1) << endl;
    }
  } else {
    cout << -1 << endl;
  }
}
