#include <bits/stdc++.h>
using namespace std;
pair<int, int> volc[100000];
int main() {
  int n, m;
  scanf("%d", &n);
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d", &volc[i].first);
    scanf("%d", &volc[i].second);
  }
  sort(volc, volc + m);
  int x = 0;
  vector<pair<int, int> > ints;
  ints.push_back(make_pair(1, 1));
  int i = 0;
  while (i != m) {
    if (ints.empty()) break;
    if (volc[i].first > x + 1) {
      int f = ints[0].first;
      ints.clear();
      ints.push_back(make_pair(f, n));
    }
    x = volc[i].first;
    vector<pair<int, int> > ys;
    int last = 0;
    while (x == volc[i].first) {
      if ((volc[i].second - last - 1) > 0)
        ys.push_back(make_pair(last + 1, volc[i].second - 1));
      last = volc[i].second;
      i++;
    }
    if ((n + 1 - last - 1) > 0) ys.push_back(make_pair(last + 1, n));
    vector<pair<int, int> > nints;
    int k = 0;
    for (int j = 0; j < (int)(ints.size()); j++) {
      while (k < (int)(ys.size()) && ys[k].second < ints[j].first) k++;
      while (k < (int)(ys.size()) && ys[k].first <= ints[j].second) {
        nints.push_back(
            make_pair(max(ys[k].first, ints[j].first), ys[k].second));
        k++;
      }
    }
    ints = nints;
  }
  if (ints.empty()) {
    cout << -1 << endl;
    return 0;
  }
  if (x != n || ints[(int)(ints.size()) - 1].second == n)
    cout << 2 * (n - 1) << endl;
  else
    cout << -1 << endl;
  return 0;
}
