#include <bits/stdc++.h>
using namespace std;
map<int, vector<int> > v;
vector<pair<int, int> > a[100004];
void chk(int x) {
  int left;
  int l = 0;
  int r = a[x - 1].size() - 1;
  vector<pair<int, int> > temp;
  for (int i = 0; i < a[x].size(); i++) {
    l = 0;
    r = a[x - 1].size() - 1;
    left = 1000000007;
    while (l <= r) {
      int mid = (l + r) / 2;
      if (a[x - 1][mid].first >= a[x][i].first &&
          a[x][i].second >= a[x - 1][mid].first) {
        left = min(left, a[x - 1][mid].first);
        r = mid - 1;
        continue;
      }
      if (a[x][i].first >= a[x - 1][mid].first &&
          a[x - 1][mid].second >= a[x][i].first) {
        left = min(left, a[x][i].first);
        r = mid - 1;
        continue;
      }
      if (a[x - 1][mid].second < a[x][i].first) {
        l = mid + 1;
      } else {
        r = mid - 1;
      }
    }
    if (left != 1000000007) temp.push_back(make_pair(left, a[x][i].second));
  }
  a[x].clear();
  a[x] = temp;
}
int main() {
  ios_base::sync_with_stdio;
  int n, i, j, k, l, m;
  cin >> n >> m;
  bool flag2 = 0;
  for (i = 0; i < m; i++) {
    cin >> k >> l;
    v[k].push_back(l);
    if (k == 1) flag2 = 1;
  }
  bool flag = 0;
  int last = 0;
  j = 0;
  for (auto it = v.begin(); it != v.end(); ++it) {
    sort(it->second.begin(), it->second.end());
    l = 1;
    if (last != it->first - 1 && j > 0) {
      l = a[j - 1][0].first;
    }
    for (auto it2 = it->second.begin(); it2 != it->second.end(); ++it2) {
      if (l <= (*it2) - 1) {
        a[j].push_back(make_pair(l, (*it2) - 1));
      }
      l = max(l, (*it2) + 1);
    }
    if (l <= n) {
      a[j].push_back(make_pair(l, n));
    }
    if (j > 0 && last == it->first - 1) {
      chk(j);
    } else if (flag2 && j == 0) {
      k = a[0][0].first;
      l = a[0][0].second;
      a[j].clear();
      a[j].push_back(make_pair(k, l));
    }
    last = it->first;
    if (a[j].size() == 0) {
      flag = 1;
      break;
    }
    j++;
  }
  if (v[n].size() > 0 && !flag) {
    flag = 1;
    if (a[v.size() - 1].size() > 0)
      if (a[v.size() - 1][a[v.size() - 1].size() - 1].second == n) flag = 0;
  }
  if (flag) {
    cout << "-1";
  } else
    cout << 2 * (n - 1);
  return 0;
}
