#include <bits/stdc++.h>
using namespace std;
struct block {
  int x, y;
  bool const operator<(const block &r) const {
    if (x == r.x) return y < r.y;
    return x < r.x;
  }
  block() {}
  block(int x, int y) : x(x), y(y) {}
};
int N, M, L, C;
block Blocks[100005], Last[100005], Cur[100005];
int main(void) {
  scanf("%d %d", &N, &M);
  for (int i = 1; i <= M; i++) scanf("%d %d", &Blocks[i].x, &Blocks[i].y);
  sort(Blocks + 1, Blocks + M + 1);
  Last[++L] = block(1, 1);
  for (int i = 1; i <= M; i++) {
    int j = 1, newy = 1;
    if (Blocks[i].x != Blocks[i - 1].x + 1) {
      L = 1;
      Last[1].y = N;
    }
    for (j = i; j <= M && Blocks[j].x == Blocks[i].x; j++)
      ;
    --j;
    C = 0;
    for (int k = i; k <= j; k++) {
      if (newy < Blocks[k].y) Cur[++C] = block(newy, Blocks[k].y - 1);
      newy = Blocks[k].y + 1;
    }
    if (newy <= N) Cur[++C] = block(newy, N);
    for (int k = 1; k <= C; k++) {
      int lo = 1, mid, hi = L, value = -1;
      while (lo <= hi) {
        mid = (lo + hi) / 2;
        if (Last[mid].y >= Cur[k].x) {
          hi = mid - 1;
          value = Last[mid].x;
        } else {
          lo = mid + 1;
        }
      }
      if (value == -1 || value > Cur[k].y)
        Cur[k].x = Cur[k].y = -1;
      else {
        Cur[k].x = max(Cur[k].x, value);
      }
    }
    L = 0;
    for (int k = 1; k <= C; k++) {
      if (Cur[k].x != -1) Last[++L] = Cur[k];
    }
    if (L == 0) {
      printf("-1\n");
      return 0;
    }
    i = j;
  }
  if (Blocks[M].x != N) {
    L = 1;
    Last[1].y = N;
  }
  if (Last[L].y == N)
    printf("%d\n", 2 * N - 2);
  else
    printf("-1\n");
  return 0;
}
