#include <bits/stdc++.h>
using namespace std;
int n, m;
int px[110000], py[110000], ppx[110000], ppy[110000];
int X[110000], Y[110000], XN, YN;
map<int, int> HX, HY;
queue<int> q;
vector<pair<int, int> > VX[110000], VY[110000];
int chk[110000];
int main() {
  int i, k, x, y;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    scanf("%d%d", px + i, py + i);
    X[XN++] = px[i], Y[YN++] = py[i];
  }
  sort(X, X + XN), XN = unique(X, X + XN) - X;
  sort(Y, Y + YN), YN = unique(Y, Y + YN) - Y;
  for (i = 0; i < XN; i++) HX[X[i]] = i;
  for (i = 0; i < YN; i++) HY[Y[i]] = i;
  for (i = 0; i < m; i++) {
    int xid = HX[px[i]];
    int yid = HY[py[i]];
    VX[xid].push_back(make_pair(py[i], i));
    VY[yid].push_back(make_pair(px[i], i));
  }
  for (i = 0; i < XN; i++) sort(VX[i].begin(), VX[i].end());
  for (i = 0; i < YN; i++) {
    sort(VY[i].begin(), VY[i].end());
    reverse(VY[i].begin(), VY[i].end());
  }
  for (i = 0; i < m; i++)
    if (px[i] == n || py[i] == 1) {
      q.push(i), chk[i] = 1;
    }
  int flag(0);
  while (!q.empty()) {
    int id = q.front();
    q.pop();
    x = px[id], y = py[id];
    if (x == 1 || y == n) {
      puts("-1");
      flag = 1;
      break;
    }
    if (HX.count(x - 1)) {
      int xid = HX[x - 1];
      while (ppx[xid] < VX[xid].size() && VX[xid][ppx[xid]].first <= y + 1) {
        int id = VX[xid][ppx[xid]++].second;
        if (chk[id]) continue;
        chk[id] = 1;
        q.push(id);
      }
    }
    if (HY.count(y + 1)) {
      int yid = HY[y + 1];
      while (ppy[yid] < VY[yid].size() && VY[yid][ppy[yid]].first >= x - 1) {
        int id = VY[yid][ppy[yid]++].second;
        if (chk[id]) continue;
        chk[id] = 1;
        q.push(id);
      }
    }
  }
  if (!flag) cout << 2 * n - 2 << endl;
}
