#include <bits/stdc++.h>
using namespace std;
const int NMAX = 200010, INF = 0x3f3f3f3f;
struct Interv {
  int X, Y;
} Blocked[NMAX], Crt[NMAX], Prev[NMAX];
int N, M, X, Y, CntCrt, CntPrev;
struct Comp {
  bool operator()(const Interv &A, const Interv &B) const {
    if (A.X == B.X) return A.Y < B.Y;
    return A.X < B.X;
  }
};
int main() {
  scanf("%i %i", &N, &M);
  for (int i = 1; i <= M; ++i) {
    scanf("%i %i", &X, &Y);
    Blocked[i].X = X;
    Blocked[i].Y = Y;
  }
  sort(Blocked + 1, Blocked + M + 1, Comp());
  CntPrev = 1;
  Prev[1].X = 1;
  Prev[1].Y = 1;
  for (int i = 1; i <= M; ++i) {
    if (Blocked[i].X != Blocked[i - 1].X + 1) {
      CntPrev = 1;
      Prev[1].Y = N;
    }
    int j;
    for (j = i; j <= M && Blocked[i].X == Blocked[j].X; ++j)
      ;
    --j;
    CntCrt = 0;
    int Left = 1;
    for (int k = i; k <= j; ++k) {
      if (Blocked[k].Y - 1 >= Left)
        Crt[++CntCrt].X = Left, Crt[CntCrt].Y = Blocked[k].Y - 1;
      Left = Blocked[k].Y + 1;
    }
    if (N >= Left) Crt[++CntCrt].X = Left, Crt[CntCrt].Y = N;
    for (int k = 1; k <= CntCrt; ++k) {
      int Left = 1, Right = CntPrev, Mid, Pos = -1;
      while (Left <= Right) {
        Mid = (Left + Right) / 2;
        if (Prev[Mid].Y >= Crt[k].X)
          Pos = Mid, Right = Mid - 1;
        else
          Left = Mid + 1;
      }
      if (Pos == -1 || Prev[Pos].X > Crt[k].Y)
        Crt[k].X = Crt[k].Y = INF;
      else
        Crt[k].X = max(Crt[k].X, Prev[Pos].X);
    }
    CntPrev = 0;
    for (int k = 1; k <= CntCrt; ++k)
      if (Crt[k].X != INF && Crt[k].Y != INF) Prev[++CntPrev] = Crt[k];
    if (CntPrev == 0) {
      printf("-1");
      return 0;
    }
    i = j;
  }
  if (Blocked[M].X != N) CntPrev = 1, Prev[1].Y = N;
  if (Prev[CntPrev].Y == N)
    printf("%i", 2 * N - 2);
  else
    printf("-1");
}
