#include <bits/stdc++.h>
using namespace std;
const int maxm = 100000 + 10;
const int inf = 0x3f3f3f3f;
struct Range {
  int x, y;
  bool operator<(const Range& rhs) const {
    if (y == rhs.y) return x < rhs.x;
    return y < rhs.y;
  }
} block[maxm], pre[maxm], cur[maxm];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) scanf("%d%d", &block[i].x, &block[i].y);
  sort(block + 1, block + 1 + m);
  block[0].x = block[0].y = 0;
  int precnt = 1, curcnt = 0;
  pre[1].x = pre[1].y = 1;
  for (int i = 1; i <= m; i++) {
    if (block[i].y != block[i - 1].y + 1) {
      pre[1].y = n;
      precnt = 1;
    }
    int j;
    for (j = i + 1; j <= m; j++)
      if (block[j].y != block[i].y) break;
    j--;
    curcnt = 0;
    int s = 1;
    for (int k = i; k <= j; k++) {
      if (block[k].x == s) {
        s++;
        continue;
      }
      cur[curcnt].x = s;
      cur[curcnt].y = block[k].x - 1;
      curcnt++;
      s = block[k].x + 1;
    }
    if (s <= n) {
      cur[curcnt].x = s;
      cur[curcnt++].y = n;
    }
    for (int k = 0; k < curcnt; k++) {
      int l = 1, r = precnt, ans = -1;
      while (l <= r) {
        int M = l + (r - l) / 2;
        if (pre[M].y >= cur[k].x) {
          ans = pre[M].x;
          r = M - 1;
        } else
          l = M + 1;
      }
      if (ans == -1 || ans > cur[k].y)
        cur[k].x = cur[k].y = inf;
      else
        cur[k].x = max(cur[k].x, ans);
    }
    precnt = 0;
    for (int k = 0; k < curcnt; k++) {
      if (cur[k].x != inf && cur[k].y != inf) pre[++precnt] = cur[k];
    }
    if (precnt == 0) {
      printf("-1\n");
      return 0;
    }
    i = j;
  }
  if (block[m].y == n && pre[precnt].y != n)
    printf("-1\n");
  else
    printf("%d\n", 2 * n - 2);
  return 0;
}
