#include <bits/stdc++.h>
using namespace std;
int n, m;
pair<int, int> v[100010];
vector<pair<int, int> > rg[100010];
set<int> row;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> v[i].first >> v[i].second;
    row.insert(v[i].first);
  }
  sort(v + 1, v + m + 1);
  rg[0].push_back(make_pair(1, 1));
  row.insert(0);
  set<int>::iterator it = row.begin(), tmp;
  it++;
  int i, j;
  for (i = 1, j = 1; it != row.end(); i++, it++) {
    tmp = it;
    bool gap = (*it - 1 != *(--tmp));
    for (int l = 0, r = 0; r <= n; j++, l = r) {
      if (j <= m && v[j].first == *it)
        r = v[j].second;
      else {
        r = n + 1;
        j--;
      }
      if (r - l <= 1) continue;
      int lo = -1, hi = (gap ? 0 : rg[i - 1].size()), mid;
      while (hi - lo > 1) {
        mid = (lo + hi) / 2;
        if (rg[i - 1][mid].second > l)
          hi = mid;
        else
          lo = mid;
      }
      if (hi == rg[i - 1].size()) continue;
      int rl = max(l + 1, rg[i - 1][hi].first);
      if (rl < r) rg[i].push_back(make_pair(rl, r - 1));
    }
    if (rg[i].empty()) {
      cout << -1;
      return 0;
    }
  }
  if (v[m].first == n)
    cout << (rg[i - 1].back().second == n ? 2 * n - 2 : -1);
  else
    cout << 2 * n - 2;
}
