#include <bits/stdc++.h>
using namespace std;
int n, m, mi;
struct nod {
  int x, y;
  nod(int X, int Y) : x(X), y(Y) {}
  nod() {}
} o[100010];
bool cmp(const nod &a, const nod &b) {
  return a.x == b.x ? a.y < b.y : a.x < b.x;
}
nod l[100010];
int lt;
nod r[100010];
int rt;
nod w[100010];
int wt;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) scanf("%d%d", &o[i].x, &o[i].y);
  sort(o + 1, o + m + 1, cmp);
  l[1] = nod(1, 1);
  l[lt = 2] = nod(2, -1);
  for (int i = 1, j; i <= m; lt = wt) {
    for (j = i + 1; o[j].x == o[i].x; ++j)
      ;
    if (o[i].x > o[i - 1].x + 1) l[lt = 2].x = n + 1;
    r[1] = nod(1, 1), r[rt = 2] = nod(n + 1, -1);
    for (; i < j; ++i) {
      r[rt].x = o[i].y;
      if (r[rt].x == r[rt - 1].x) rt -= 2;
      r[++rt] = nod(o[i].y + 1, 1), r[++rt] = nod(n + 1, -1);
    }
    if (r[rt].x == r[rt - 1].x) rt -= 2;
    int lres = 0, rres = 0;
    wt = 0;
    for (int a = 1, b = 1, x; a <= lt || b <= rt;) {
      if ((l[a].x <= r[b].x || b > rt) && a <= lt)
        x = l[a].x, lres += l[a++].y;
      else
        x = r[b].x, rres += r[b++].y;
      if (lres && rres) rres = 0, w[++wt] = nod(x, 1), w[++wt] = r[b++];
      if (w[wt].x == w[wt - 1].x && wt) wt -= 2;
    }
    if (wt == 0) {
      printf("-1\n");
      return 0;
    }
    for (int j = 1; j <= wt; ++j) l[j] = w[j];
  }
  if ((o[m].x == n && lt && l[lt].x > n && l[lt - 1].x <= n) ||
      (o[m].x < n && lt))
    printf("%d\n", 2 * n - 2);
  else
    printf("-1\n");
  return 0;
}
