#include <bits/stdc++.h>
using namespace std;
template <class T>
void debug(T a, T b) {
  ;
}
template <class T>
void chmin(T& a, const T& b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T& a, const T& b) {
  if (a < b) a = b;
}
namespace std {
template <class S, class T>
ostream& operator<<(ostream& out, const pair<S, T>& a) {
  out << '(' << a.first << ',' << a.second << ')';
  return out;
}
}  // namespace std
long long int readL() {
  long long int res;
  scanf("%I64d", &res);
  return res;
}
void printL(long long int res) { printf("%I64d", res); }
const int INF = 5e8;
int n, m;
pair<int, int> ps[100005];
int main() {
  cin >> n >> m;
  for (int i = 0; i < (m); ++i) {
    scanf("%d%d", &ps[i].first, &ps[i].second);
    --ps[i].first;
    --ps[i].second;
  }
  sort(ps, ps + m);
  int cur = 0;
  set<pair<int, int> > seg, nxt;
  seg.insert(make_pair(0, 1));
  vector<int> x;
  for (int i = 0; i < (m); ++i) {
    int j = i;
    if (seg.empty()) {
      puts("-1");
      return 0;
    }
    if (cur < ps[i].first) {
      int left = seg.begin()->first;
      seg.clear();
      seg.insert(make_pair(left, n));
    };
    ;
    debug((seg).begin(), (seg).end());
    x.clear();
    x.push_back(-1);
    while (j < m && ps[j].first == ps[i].first) {
      x.push_back(ps[j].second);
      ++j;
    }
    x.push_back(n);
    for (int k = 0; k < (x.size() - 1); ++k) {
      int l = x[k] + 1, r = x[k + 1];
      if (l >= r) continue;
      ;
      ;
      auto it = seg.lower_bound(make_pair(l, INF));
      if (it != seg.begin()) {
        --it;
        if (it->second > l) {
          nxt.insert(make_pair(l, r));
          continue;
        }
      }
      it = seg.lower_bound(make_pair(l, INF));
      if (it != seg.end() && it->first < r) nxt.insert(make_pair(it->first, r));
    }
    cur = ps[i].first + 1;
    i = j - 1;
    seg = nxt;
    nxt.clear();
  }
  debug((seg).begin(), (seg).end());
  if (cur == n) {
    if (!seg.empty()) {
      auto it = seg.end();
      --it;
      if (it->second == n) {
        printf("%d\n", n * 2 - 2);
        return 0;
      }
    }
    puts("-1");
  } else {
    ;
    ;
    if (!seg.empty()) {
      if (seg.begin()->first < n) {
        printf("%d\n", n * 2 - 2);
        return 0;
      }
    }
    puts("-1");
  }
  return 0;
}
