#include <bits/stdc++.h>
using namespace std;
int main(void) {
  srand(time(0));
  cout << fixed << setprecision(7);
  cerr << fixed << setprecision(7);
  int n, m;
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  const int was = n + n - 2;
  vector<pair<int, int> > s;
  vector<int> sx, sy;
  while (m--) {
    int a, b;
    cin >> a >> b;
    s.push_back({a, b});
    sx.push_back(a);
    if (a > 1) sx.push_back(a - 1);
    if (a < b) sx.push_back(a + 1);
    sy.push_back(b);
    if (b > 1) sy.push_back(b - 1);
    if (b < n) sy.push_back(b + 1);
  }
  sx.push_back(n);
  sy.push_back(n);
  sort(sx.begin(), sx.end());
  sort(sy.begin(), sy.end());
  sx.resize(unique(sx.begin(), sx.end()) - sx.begin());
  sy.resize(unique(sy.begin(), sy.end()) - sy.begin());
  for (auto& it : s)
    it.first = lower_bound(sx.begin(), sx.end(), it.first) - sx.begin() + 1,
    it.second = lower_bound(sy.begin(), sy.end(), it.second) - sy.begin() + 1;
  static vector<int> v[1 << 20];
  sort(s.begin(), s.end());
  n = sy.size();
  m = sx.size();
  for (int i = 1; i <= m; ++i) v[i].push_back(0);
  for (auto it : s) v[it.first].push_back(it.second);
  for (int i = 1; i <= m; ++i) v[i].push_back(n + 1);
  set<pair<int, int> > w1;
  w1.insert({1, v[1][1] - 1});
  for (int i = 2; i <= m; ++i) {
    static int mx[1 << 20];
    auto vv = v[i];
    int sz = vv.size();
    for (int i = 0; i < sz; ++i) mx[i] = 0;
    int cnt = 0;
    while (!w1.empty()) {
      while (vv[cnt + 1] < w1.begin()->first) ++cnt;
      if (!mx[cnt] && w1.begin()->first > vv[cnt] &&
          w1.begin()->first < vv[cnt + 1])
        mx[cnt] = w1.begin()->first;
      if (w1.begin()->second > vv[cnt + 1])
        w1.insert({vv[cnt + 1] + 1, w1.begin()->second});
      w1.erase(w1.begin());
    }
    for (int i = 0; i < sz - 1; ++i)
      if (mx[i] && mx[i] < vv[i + 1]) w1.insert({mx[i], vv[i + 1] - 1});
  }
  if (!w1.empty() && w1.rbegin()->second == n)
    cout << was << '\n';
  else
    cout << "-1\n";
  cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms"
       << '\n';
  return 0;
}
