#include <bits/stdc++.h>
using namespace std;
struct point {
  int x, y;
};
bool operator<(point a, point b) {
  return (a.x == b.x) ? (a.y < b.y) : (a.x < b.x);
}
struct Interval {
  int l, r;
};
int get() {
  char c;
  while (c = getchar(), (c < '0' || c > '9') && (c != '-'))
    ;
  bool flag = (c == '-');
  if (flag) c = getchar();
  int x = 0;
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - 48;
    c = getchar();
  }
  return flag ? -x : x;
}
void output(int x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  int len = 0, data[10];
  while (x) {
    data[len++] = x % 10;
    x /= 10;
  }
  if (!len) data[len++] = 0;
  while (len--) putchar(data[len] + 48);
  putchar('\n');
}
point p[100000];
bool check(int n, int m) {
  if (!m) return true;
  int currentline = 1, total = 1;
  static Interval a[200000], a0[200000];
  if (p[0].x > 1)
    a[0] = (Interval){1, n};
  else
    a[0] = (Interval){1, p[0].y - 1};
  for (int i = 0, j; total && i < m; i = j) {
    j = i + 1;
    while (j < m && p[i].x == p[j].x) j++;
    if (p[i].x == 1) continue;
    if (p[i].x > currentline + 1) {
      total = 1;
      a[0].r = n;
    }
    currentline = p[i].x;
    static int b[100002];
    int tot = 0;
    b[tot++] = 0;
    for (int k = i; k < j; k++) b[tot++] = p[k].y;
    b[tot++] = n + 1;
    int newtotal = 0;
    for (int k = 1, kk = 0; k < tot && kk < total; k++) {
      while (kk < total && a[kk].r <= b[k - 1]) kk++;
      if (kk == total) break;
      if (a[kk].l >= b[k]) continue;
      if (a[kk].l <= b[k - 1]) a[kk].l = b[k - 1] + 1;
      if (a[kk].l < b[k]) a0[newtotal++] = (Interval){a[kk].l, b[k] - 1};
      a[kk].l = b[k] + 1;
      if (a[kk].l > a[kk].r) kk++;
    }
    total = newtotal;
    for (int k = 0; k < newtotal; k++) a[k] = a0[k];
  }
  if (total && p[m - 1].x < n) return true;
  return total && a[total - 1].r == n;
}
int main() {
  int n = get(), m = get();
  for (int i = 0; i < m; i++) {
    p[i].x = get();
    p[i].y = get();
  }
  sort(p, p + m);
  if (check(n, m))
    output(n * 2 - 2);
  else
    output(-1);
  return 0;
}
