#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:36777216")
using namespace std;
struct Point {
  int r, c;
} p[111111];
struct seg {
  int r, cl, cr;
  seg(){};
  seg(int a, int b, int c) { r = a, cl = b, cr = c; }
};
bool cmp_p(const Point &a, const Point &b) {
  if (a.r != b.r) return a.r < b.r;
  return a.c < b.c;
}
int n, m;
vector<seg> vec;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) scanf("%d%d", &p[i].r, &p[i].c);
  sort(p + 1, p + 1 + m, cmp_p);
  bool FLAG = true;
  for (int i = 1; i <= m; i++) {
    int pre = 1, row = p[i].r;
    for (; i <= m; i++) {
      if (p[i].r != row) break;
      if (p[i].c != pre) vec.push_back(seg(p[i].r, pre, p[i].c - 1));
      pre = p[i].c + 1;
    }
    i--;
    if (pre != n + 1) vec.push_back(seg(p[i].r, pre, n));
    if (pre == n + 1) {
      if (vec.size() == 0 || vec[vec.size() - 1].r != row) FLAG = false;
    }
  }
  if (!FLAG) {
    printf("-1\n");
    return 0;
  }
  vector<seg> now;
  now.push_back(seg(0, 1, 1));
  int prerow = 0;
  for (int i = 0; i < vec.size(); i++) {
    int row = vec[i].r;
    if (now.empty()) break;
    if (row != now[0].r + 1) {
      int fst = now[0].cl;
      now.clear();
      for (; i < vec.size(); i++) {
        if (vec[i].r != row) break;
        if (vec[i].cr < fst)
          continue;
        else if (fst <= vec[i].cl)
          now.push_back(vec[i]);
        else
          now.push_back(seg(vec[i].r, fst, vec[i].cr));
      }
      i--;
    } else {
      int j = 0;
      vector<seg> tempnow;
      for (; i < vec.size(); i++) {
        if (vec[i].r != row) break;
        while (now[j].cr < vec[i].cl && j < now.size()) j++;
        if (j != now.size() && now[j].cl <= vec[i].cr) {
          tempnow.push_back(
              seg(vec[i].r, max(vec[i].cl, now[j].cl), vec[i].cr));
        }
      }
      i--;
      now = tempnow;
    }
  }
  if (now.empty() || (now[0].r == n && now[now.size() - 1].cr < n))
    printf("-1\n");
  else
    printf("%d\n", 2 * n - 2);
}
