#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200015;
vector<int> obstacles[MAXN];
vector<pair<int, int> > o;
map<pair<int, int>, int> iso, see;
map<pair<pair<int, int>, pair<int, int> >, int> vis;
map<int, int> ir, ic, cr, cc, icc;
int cntr = 1, cntc = 1;
int n, m;
void dfs(int x, int y) {
  if (x < 1 || x > cntr || y < 1 || y > cntc) return;
  if (iso[pair<int, int>(x, y)]) return;
  vector<int> &u = obstacles[y];
  auto T = lower_bound(u.begin(), u.end(), x);
  auto S = T;
  S--;
  int sin = x, ein = (*T) - 1;
  if (vis.count(pair<pair<int, int>, pair<int, int> >(
          pair<int, int>((*S) + 1, y), pair<int, int>((*T) - 1, y))))
    return;
  vis[pair<pair<int, int>, pair<int, int> >(pair<int, int>((*S) + 1, y),
                                            pair<int, int>((*T) - 1, y))] = 1;
  see[pair<int, int>((*T) - 1, y)] = 1;
  dfs(x, y + 1);
  if (y != cntc) {
    vector<int> &r = obstacles[y + 1];
    auto ER = lower_bound(r.begin(), r.end(), x) - r.begin();
    for (int g = ER; g < r.size(); g++) {
      if (r[g] >= ein) break;
      dfs(r[g] + 1, y + 1);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int g = 0; g < m; g++) {
    int a, b;
    cin >> a >> b;
    if (a == n && b == n) {
      cout << -1;
      return 0;
    }
    ic[b] = 1;
    o.push_back(pair<int, int>(a, b));
  }
  for (auto x = ic.begin(); x != ic.end(); x++) {
    icc[(x->first)] = 1;
    auto y = x;
    y++;
    if (y == ic.end()) continue;
    if ((y->first) - (x->first) != 1) {
      icc[x->first + 1] = 1;
    }
  }
  if (icc[1] == 0) icc[1] = 1;
  if (icc[n] == 0) icc[n] = 1;
  for (auto x = icc.begin(); x != icc.end(); x++) {
    cc[x->first] = cntc++;
  }
  cntr = n;
  cntc--;
  for (int g = 0; g < MAXN; g++) {
    obstacles[g].push_back(0);
    obstacles[g].push_back(cntr + 1);
  }
  for (int g = 0; g < o.size(); g++) o[g].second = cc[o[g].second];
  for (int g = 0; g < o.size(); g++)
    iso[pair<int, int>(o[g].first, o[g].second)] = 1;
  for (int g = 0; g < o.size(); g++)
    obstacles[o[g].second].push_back(o[g].first);
  for (int g = 0; g < MAXN; g++) sort(obstacles[g].begin(), obstacles[g].end());
  dfs(1, 1);
  if (see[pair<int, int>(cntr, cntc)])
    cout << 2 * n - 2;
  else
    cout << -1;
  return 0;
}
