#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, y;
} a[100005], S[1000005], s[1000005];
int R, n, m, i, now, j, k, L, o;
int cmp(node i, node j) { return i.y < j.y || (i.y == j.y && i.x < j.x); }
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= m; i++) scanf("%d%d", &a[i].x, &a[i].y);
  sort(a + 1, a + m + 1, cmp);
  now = 0;
  R = 1;
  s[1].x = 1;
  s[1].y = 1;
  for (i = 1; i <= m; i++) {
    for (j = i + 1; j <= m && a[j].y == a[i].y; j++)
      ;
    j--;
    if (a[i].y - a[i - 1].y > 1) {
      R = 1;
      s[1].y = n;
    }
    o = 0;
    L = i;
    for (k = 1; k <= R; k++) {
      while (L <= j && a[L].x < s[k].x) L++;
      while (L <= j && a[L].x <= s[k].y) {
        if (a[L].x > s[k].x) {
          S[++o].x = s[k].x;
          S[o].y = a[L].x - 1;
        }
        s[k].x = a[L].x + 1;
        L++;
      }
      if (L > j && s[k].x <= s[k].y) {
        S[++o].x = s[k].x;
        S[o].y = n;
      }
      if (L <= j && a[L].x > s[k].y && a[L].x > s[k].x && s[k].x <= s[k].y) {
        S[++o].x = s[k].x;
        S[o].y = a[L].x - 1;
      }
    }
    sort(S + 1, S + o + 1, cmp);
    if (!o) {
      cout << -1 << endl;
      return 0;
    }
    R = 1;
    s[1].x = S[1].x;
    s[1].y = S[1].y;
    for (k = 2; k <= o; k++) {
      if (S[k].y == s[R].y) continue;
      if (S[k].x <= s[R].y)
        s[R].y = S[k].y;
      else {
        s[++R].x = S[k].x;
        s[R].y = S[k].y;
      }
    }
    if (!R) {
      cout << -1;
      return 0;
    }
    i = j;
  }
  if (s[R].y != n && a[m].y == n)
    cout << -1;
  else
    cout << n * 2 - 2;
  return 0;
}
