#include <bits/stdc++.h>
using namespace std;
const int SZ = 100000 + 10;
int g_n, g_m;
queue<pair<int, int> > q;
vector<pair<int, int> > vpii;
map<pair<int, int>, bool> mpb_vis;
map<int, vector<int> > mivi_x;
map<int, vector<int> > mivi_y;
void prete() {}
void input() {
  vpii.clear();
  mpb_vis.clear();
  mivi_x.clear();
  mivi_y.clear();
  while (!q.empty()) q.pop();
  pair<int, int> p;
  for (int i = 0; i < g_m; ++i) {
    scanf(" %d %d", &p.first, &p.second);
    vpii.push_back(p);
    mivi_x[p.first].push_back(p.second);
    mivi_y[p.second].push_back(p.first);
    if (p.first == 1) {
      q.push(p);
      mpb_vis[p] = true;
    }
    if (p.second == g_n) {
      q.push(p);
      mpb_vis[p] = true;
    }
  }
}
void solve() {
  map<int, vector<int> >::iterator mvit;
  for (mvit = mivi_x.begin(); mvit != mivi_x.end(); ++mvit) {
    sort(mvit->second.begin(), mvit->second.end());
  }
  for (mvit = mivi_y.begin(); mvit != mivi_y.end(); ++mvit) {
    sort(mvit->second.begin(), mvit->second.end());
  }
  bool f = false;
  while (!q.empty()) {
    pair<int, int> p = q.front();
    q.pop();
    mpb_vis[p] = true;
    if (p.first == g_n || p.second == 1) {
      f = true;
      break;
    }
    map<int, vector<int> >::iterator mivit_x = mivi_x.find(p.first + 1);
    if (mivit_x != mivi_x.end()) {
      vector<int> &vy = mivit_x->second;
      for (int i = vy.size() - 1; i >= 0; --i) {
        if (vy[i] < p.second - 1) {
          break;
        }
        pair<int, int> tp = pair<int, int>(p.first + 1, vy[i]);
        if (!mpb_vis[tp]) {
          mpb_vis[tp] = true;
          q.push(tp);
        }
      }
    }
    map<int, vector<int> >::iterator mivit_y = mivi_y.find(p.second - 1);
    if (mivit_y != mivi_y.end()) {
      vector<int> &vx = mivit_y->second;
      for (int i = 0; i < vx.size(); ++i) {
        if (vx[i] > p.first + 1) break;
        pair<int, int> tp = pair<int, int>(vx[i], p.second - 1);
        if (!mpb_vis[tp]) {
          mpb_vis[tp] = true;
          q.push(tp);
        }
      }
    }
  }
  if (!f) {
    printf("%d\n", 2 * g_n - 2);
  } else {
    printf("-1\n");
  }
}
int main() {
  prete();
  while (scanf(" %d %d", &g_n, &g_m) != EOF) {
    input();
    solve();
  }
  return 0;
}
