#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000100;
typedef struct {
  int x, y;
} Node;
Node pre[100005], now[100005], blocked[100005];
bool comp(Node a, Node b) {
  if (a.x == b.x) return a.y < b.y;
  return a.x < b.x;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> blocked[i].x >> blocked[i].y;
  }
  sort(blocked + 1, blocked + m + 1, comp);
  int cp = 0, pp = 1;
  pre[1].x = 1;
  pre[1].y = 1;
  for (int i = 1; i <= m; i++) {
    if (blocked[i].x != blocked[i - 1].x + 1) {
      pp = 1;
      pre[pp].y = n;
    }
    int j;
    for (j = i; j <= m && blocked[j].x == blocked[i].x; j++)
      ;
    j--;
    cp = 0;
    int leftseg = 1;
    for (int k = i; k <= j; k++) {
      if (blocked[k].y > leftseg) {
        now[++cp].x = leftseg;
        now[cp].y = blocked[k].y - 1;
      }
      leftseg = blocked[k].y + 1;
    }
    if (leftseg <= n) {
      now[++cp].x = leftseg;
      now[cp].y = n;
    }
    for (int k = 1; k <= cp; k++) {
      int s = 1, e = pp, ret = -1;
      while (s <= e) {
        int mid = (s + e) / 2;
        if (pre[mid].y >= now[k].x) {
          ret = pre[mid].x;
          e = mid - 1;
        } else {
          s = mid + 1;
        }
      }
      if (ret == -1 || ret > now[k].y) {
        now[k].x = now[k].y = INF;
      } else
        now[k].x = max(ret, now[k].x);
    }
    pp = 0;
    for (int k = 1; k <= cp; k++) {
      if (now[k].x != INF && now[k].y != INF) {
        pre[++pp] = now[k];
      }
    }
    if (pp == 0) {
      cout << -1 << endl;
      return 0;
    }
    i = j;
  }
  if (pre[pp].y == n) {
    cout << n * 2 - 2 << endl;
  } else if (blocked[m].x != n) {
    cout << n * 2 - 2 << endl;
  } else
    cout << -1 << endl;
}
