#include <bits/stdc++.h>
using namespace std;
struct st {
  int x, y;
} point[200000];
struct xd {
  int start;
  int end, xx;
} li[200000];
int m, n;
int l[200000], r[200000], vis[200000];
int cam(const void *x, const void *y) {
  struct st p = *(struct st *)x;
  struct st q = *(struct st *)y;
  if (p.x == q.x) return p.y - q.y;
  return p.x - q.x;
}
void debug(int cnt) {
  int i, j;
  for (i = 0; i <= cnt; i++) {
    for (j = l[i]; j < r[i]; j++) {
      printf("%d %d %d\n", li[j].start, li[j].end, li[j].xx);
    }
  }
}
int check() {
  memset(vis, 0, sizeof(vis));
  int i, j, ans = 0, index = 1, cnt = 0;
  for (i = 0; i < m; i++) {
    if (i == 0) {
      l[0] = 0;
    }
    if (i != 0 && point[i].x != point[i - 1].x) {
      if (point[i - 1].y != n)
        li[ans].start = index, li[ans].end = n, li[ans].xx = point[i - 1].x,
        ans++;
      r[cnt] = ans, l[++cnt] = ans;
      index = 1;
    }
    if (point[i].y == index) {
      index++;
      continue;
    }
    li[ans].start = index, li[ans].end = point[i].y - 1,
    li[ans].xx = point[i].x, ans++, index = point[i].y + 1;
  }
  if (point[i - 1].y != n)
    li[ans].start = index, li[ans].end = n, li[ans].xx = point[i - 1].x, ans++;
  r[cnt] = ans;
  if (!ans) return 0;
  if (li[0].xx == 1) {
    vis[0] = 1;
  } else {
    for (i = l[0]; i < r[0]; i++) vis[i] = 1;
  }
  int minnum = li[0].start;
  ;
  for (i = 1; i <= cnt; i++) {
    if (l[i] == r[i] || l[i - 1] == r[i - 1]) return 0;
    if (li[l[i]].xx != li[l[i - 1]].xx + 1)
      r[i - 1] = l[i - 1] + 1, li[l[i - 1]].start = minnum,
            li[l[i - 1]].end = n, vis[l[i - 1]] = 1;
    int x = l[i - 1];
    minnum = 2000000000;
    for (j = l[i]; j < r[i]; j++) {
      while ((li[x].end < li[j].start || !vis[x]) && x < r[i - 1]) x++;
      if (x >= r[i - 1]) break;
      if (li[j].start >= li[x].start && li[j].start <= li[x].end)
        vis[j] = 1;
      else if (li[j].end >= li[x].start && li[j].end <= li[x].end)
        vis[j] = 1, li[j].start = li[x].start;
      else if (li[j].start <= li[x].start && li[j].end >= li[x].end)
        vis[j] = 1, li[j].start = li[x].start;
      if (minnum > li[j].start) minnum = li[j].start;
    }
    if (minnum == 2000000000) return 0;
  }
  if (point[m - 1].x == n) {
    for (i = l[cnt]; i < r[cnt]; i++)
      if (vis[i] && li[i].start <= n && li[i].end >= n) return 1;
    return 0;
  }
  for (i = l[cnt]; i < r[cnt]; i++)
    if (vis[i]) return 1;
  return 0;
}
int main() {
  while (scanf("%d %d", &n, &m) != EOF) {
    for (int i = 0; i < m; i++) scanf("%d %d", &point[i].x, &point[i].y);
    qsort(point, m, sizeof(point[0]), cam);
    if (check())
      printf("%d\n", 2 * n - 2);
    else
      printf("-1\n");
  }
  return 0;
}
