#include <bits/stdc++.h>
const long double eps = 1e-9;
const double pi = acos(-1.0);
const long long inf = 1e18;
using namespace std;
int n, m;
vector<pair<int, int> > v, p, _new;
int main(int argc, const char* argv[]) {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    v.push_back(make_pair(x, y));
  }
  sort(v.begin(), v.end());
  p.push_back(make_pair(1, 1));
  int xx = 0;
  for (int l = 0; l < v.size();) {
    int r = l;
    while (r + 1 < v.size() && v[l].first == v[r + 1].first) r++;
    int _xx = v[l].first;
    if (xx + 1 < _xx) {
      _new.push_back(make_pair(p[0].first, n));
      p = _new;
      _new.clear();
    }
    int lst = 1;
    for (int i = l; i <= r; i++) {
      int cur = v[i].second;
      if (cur == lst) {
        lst++;
        continue;
      }
      int ll = lst, rr = cur - 1;
      _new.push_back(make_pair(ll, rr));
      lst = cur + 1;
    }
    int cur = n + 1;
    if (lst < cur) {
      int ll = lst, rr = cur - 1;
      _new.push_back(make_pair(ll, rr));
    }
    vector<pair<int, int> > _p;
    for (int i = 0; i < _new.size(); i++) {
      int l = _new[i].first;
      int r = _new[i].second;
      int id = 0;
      if (p.back().second < l) continue;
      if (p[0].second < l) {
        int ll = 1, rr = p.size() - 1, res = 0;
        while (ll <= rr) {
          int xx = (ll + rr) / 2;
          if (p[xx].second < l) {
            res = max(res, xx);
            ll = xx + 1;
          } else
            rr = xx - 1;
        }
        id = res + 1;
      }
      int _l = max(p[id].first, l);
      int _r = r;
      if (_l <= _r) _p.push_back(make_pair(_l, _r));
    }
    p = _p;
    if (p.size() == 0) break;
    _new.clear();
    xx = _xx;
    l = r + 1;
  }
  if (p.size() > 0 && xx < n) p.back().second = n;
  if (p.size() == 0 || p.back().second != n)
    printf("-1\n");
  else
    printf("%d\n", n + n - 2);
  return 0;
}
