#include <bits/stdc++.h>
int pa[100005], pb[100005], a[100005], b[100005], x[100005], y[100005],
    a1[100005];
int n, m, pn, p, c, cn, p1, min, cnt;
void qsort(int p, int r) {
  if (p >= r) return;
  int l = (p + r) / 2, t;
  t = x[l];
  x[l] = x[p];
  x[p] = t;
  t = y[l];
  y[l] = y[p];
  y[p] = t;
  int i = p, j = r, pl = x[p], pl2 = y[p];
  while (i < j) {
    while (j > i && (x[j] > pl || x[j] == pl && y[j] > pl2)) j--;
    if (i < j) {
      x[i] = x[j];
      y[i] = y[j];
      i++;
    }
    while (j > i && (x[i] < pl || x[i] == pl && y[i] < pl2)) i++;
    if (i < j) {
      x[j] = x[i];
      y[j] = y[i];
      j--;
    }
  }
  x[i] = pl;
  y[i] = pl2;
  qsort(p, i - 1);
  qsort(i + 1, r);
}
int max(int x, int y) {
  if (x > y)
    return x;
  else
    return y;
}
int find(int l, int r, int a) {
  while (l <= r) {
    if (l == r && pb[l] >= a)
      return max(pa[l], a);
    else if (l == r && pb[l] < a)
      return n + 1;
    if (pb[(l + r) / 2] >= a)
      r = (l + r) / 2;
    else
      l = (l + r) / 2 + 1;
  }
  return n + 1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) scanf("%d%d", &x[i], &y[i]);
  qsort(1, m);
  if (x[1] == 1) {
    pn = 1;
    pa[1] = 1;
    pb[1] = 1;
    p = 1;
  } else {
    pn = 1;
    pa[1] = 1;
    pb[1] = n;
    p = 1;
  }
  while (p <= m) {
    c = x[p];
    p1 = p;
    cn = 0;
    while (p1 <= m && x[p1] == c) {
      if (y[p1] == y[p] && y[p1] != 1) {
        cn++;
        a[cn] = 1;
        b[cn] = y[p1] - 1;
      } else if (y[p1] > y[p1 - 1] + 1) {
        cn++;
        a[cn] = y[p1 - 1] + 1;
        b[cn] = y[p1] - 1;
      }
      if ((p1 + 1 > m || x[p1 + 1] != x[p1]) && y[p1] != n) {
        cn++;
        a[cn] = y[p1] + 1;
        b[cn] = n;
      }
      p1++;
    }
    p1--;
    cnt = 0;
    for (int i = 1; i <= cn; i++) {
      a1[i] = find(1, pn, a[i]);
      if (a1[i] <= b[i]) {
        cnt++;
        a[cnt] = a1[i];
        b[cnt] = b[i];
      }
    }
    cn = cnt;
    if ((p1 < m && x[p1 + 1] > x[p1] + 1) || (p1 == m && x[p1] != n)) {
      min = n + 1;
      for (int i = 1; i <= cn; i++)
        if (min >= a[i]) min = a[i];
      if (cn != 0) {
        cn = 1;
        a[1] = min;
        b[1] = n;
      }
    }
    for (int i = 1; i <= cn; i++) {
      pa[i] = a[i];
      pb[i] = b[i];
    }
    pn = cn;
    p = p1 + 1;
  }
  if (b[cn] == n)
    printf("%d", n + n - 2);
  else
    printf("-1");
  return 0;
}
