#include <bits/stdc++.h>
using namespace std;
int n, m;
struct node {
  int x, y;
  node(int x = 0, int y = 0) : x(x), y(y) {}
  bool operator<(const node a) const {
    return y < a.y || (y == a.y && x < a.x);
  }
} block[100010], step[100010], cur[100010];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) scanf("%d%d", &block[i].x, &block[i].y);
  sort(block, block + m);
  int cnt = 1;
  step[0].x = 1, step[0].y = 1;
  for (int i = 0; i < m; ++i) {
    if (block[i].y != block[i - 1].y + 1) {
      cnt = 1;
      step[0].y = n;
    }
    int k = i + 1, temp = 0, total = 0, t = 0;
    while (block[k].y == block[i].y) ++k;
    --k;
    for (int j = i; j <= k; j++) {
      if (block[j].x > temp + 1) cur[total++] = node(temp + 1, block[j].x - 1);
      temp = block[j].x;
    }
    if (n > temp) cur[total++] = node(temp + 1, n);
    for (int i = 0; i < cnt; i++) {
      while (cur[t].x <= step[i].y && t < total) {
        if (cur[t].y >= step[i].x)
          cur[t].x = max(cur[t].x, step[i].x);
        else
          cur[t].x = cur[t].y = -1;
        t++;
      }
      if (t >= total) break;
    }
    cnt = 0;
    for (int i = 0; i < t; i++)
      if (cur[i].x != -1 && cur[i].y != -1) {
        step[cnt].x = cur[i].x;
        step[cnt++].y = cur[i].y;
      }
    if (!cnt) {
      puts("-1");
      return 0;
    }
    i = k;
  }
  if (block[m - 1].y != n || step[cnt - 1].y == n) {
    printf("%d\n", 2 * n - 2);
    return 0;
  }
  puts("-1");
}
