#include <bits/stdc++.h>
using namespace std;
long long dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
long long dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
int32_t main() {
  long long n, m;
  cin >> n >> m;
  vector<pair<long long, long long>> vec(m);
  vector<long long> fi;
  for (long long i = 0; i < (long long)m; ++i) {
    cin >> vec[i].first >> vec[i].second;
    fi.push_back(vec[i].first);
    if (vec[i].first < n) fi.push_back(vec[i].first + 1);
  }
  vector<pair<long long, long long>> ranges[2];
  fi.push_back(0);
  fi.push_back(1);
  fi.push_back(n);
  sort(fi.begin(), fi.end());
  fi.erase(unique(fi.begin(), fi.end()), fi.end());
  vector<vector<long long>> vol(fi.size());
  for (long long i = 0; i < (long long)m; ++i) {
    vol[lower_bound(fi.begin(), fi.end(), vec[i].first) - fi.begin()].push_back(
        vec[i].second);
  }
  for (long long i = 0; i < (long long)fi.size(); ++i)
    sort(vol[i].begin(), vol[i].end());
  long long now = 0;
  ranges[0].push_back({1, 1});
  for (long long i = 0; i < (long long)fi.size() - 1; ++i) {
    long long nxt = now ^ 1;
    ranges[nxt].clear();
    long long itr = 0;
    long long usable = 1;
    for (long long j = 0; j < ranges[now].size(); j++) {
      usable = max(usable, ranges[now][j].first);
      while (itr < vol[i + 1].size() && vol[i + 1][itr] < ranges[now][j].first)
        itr++;
      while (itr < vol[i + 1].size() &&
             vol[i + 1][itr] <= ranges[now][j].second) {
        if (usable < vol[i + 1][itr])
          ranges[nxt].push_back({usable, vol[i + 1][itr] - 1});
        usable = vol[i + 1][itr] + 1;
        itr++;
      }
      if (usable <= ranges[now][j].second) {
        if (itr < vol[i + 1].size()) {
          ranges[nxt].push_back({usable, vol[i + 1][itr] - 1});
          usable = vol[i + 1][itr] + 1;
          itr++;
        } else {
          ranges[nxt].push_back({usable, n});
          usable = n + 1;
        }
      }
    }
    now = nxt;
  }
  if (ranges[now].size() && ranges[now].back().second == n)
    cout << n * 2 - 2 << '\n';
  else
    cout << "-1\n";
  return 0;
}
