#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 1;
vector<pair<int, int> > a, b, d, pro;
vector<int> c;
int main() {
  int i, j, m, n, x, y, t, pr, z, ymin, pa, pb, mid, e;
  scanf("%d%d", &n, &m);
  for (i = 0; i < m; i++) {
    scanf("%d%d", &x, &y);
    a.push_back(make_pair(x, y));
  }
  sort(a.begin(), a.end());
  pr = 0;
  i = 0;
  b.push_back(make_pair(1, 1));
  while (i < m) {
    t = a[i].first;
    j = i;
    while ((j < m) && (a[j].first == t)) j++;
    d.resize(0);
    if (a[i].second > 1) {
      d.push_back(make_pair(1, a[i].second - 1));
    }
    for (z = i + 1; z < j; z++) {
      if (a[z].second > a[z - 1].second + 1)
        d.push_back(make_pair(a[z - 1].second + 1, a[z].second - 1));
    }
    if (a[j - 1].second < n) {
      d.push_back(make_pair(a[j - 1].second + 1, n));
    }
    if (pr < t - 1) {
      ymin = b[0].first;
      b.resize(0);
      if (d.size() == 0) {
        printf("-1");
        return 0;
      }
      for (z = 0; z < d.size(); z++) {
        if (ymin <= d[z].second) {
          if (d[z].first <= ymin)
            b.push_back(make_pair(ymin, d[z].second));
          else
            b.push_back(d[z]);
        }
      }
    } else {
      pro.resize(0);
      for (z = 0; z < d.size(); z++) {
        if (b[b.size() - 1].second < d[z].first) break;
        pa = 0;
        pb = b.size();
        while (pa != pb - 1) {
          mid = (pa + pb) / 2;
          if (b[mid].second >= d[z].first)
            pb = mid;
          else
            pa = mid;
        }
        if (b[pa].second < d[z].first) pa++;
        if (b[pa].first <= d[z].second) {
          pro.push_back(make_pair(max(d[z].first, b[pa].first), d[z].second));
        }
      }
      b.resize(0);
      for (z = 0; z < pro.size(); z++) b.push_back(pro[z]);
      if (!b.size()) {
        printf("-1");
        return 0;
      }
    }
    pr = t;
    i = j;
  }
  if (n == pr) {
    if ((b.size()) && (b[b.size() - 1].second == n))
      printf("%d", 2 * n - 2);
    else
      printf("-1");
  } else {
    if (b.size())
      printf("%d", 2 * n - 2);
    else
      printf("-1");
  }
  return 0;
}
