#include <bits/stdc++.h>
using namespace std;
const int maxm = 112345;
int n, m;
pair<int, int> blks[maxm];
int main() {
  scanf("%d%d", &n, &m);
  for (int(i) = (0); (i) <= ((m)-1); (i)++)
    scanf("%d%d", &blks[i].first, &blks[i].second);
  sort(blks, blks + m);
  vector<pair<int, int> > now, nxt;
  now.emplace_back(1, 1);
  int j = 0, px = 0;
  while (j < m) {
    if (blks[j].first != px + 1 && !now.empty()) {
      int lo = now[0].first;
      now = {make_pair(lo, n)};
    }
    int nj = j;
    while (nj < m && blks[nj].first == blks[j].first) nj++;
    nxt.clear();
    int last = 1, k = 0;
    for (int(i) = (j); (i) <= (nj); (i)++) {
      int en = i < nj ? blks[i].second : n + 1;
      while (k < now.size() && now[k].second < last) k++;
      if (k < now.size() && max(last, now[k].first) < en)
        nxt.emplace_back(max(last, now[k].first), en - 1);
      last = blks[i].second + 1;
    }
    now = nxt;
    px = blks[j].first;
    j = nj;
  }
  printf("%d",
         !now.empty() && (px < n || now.back().second == n) ? 2 * n - 2 : -1);
}
