#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  vector<pair<int, int> > sopka(m);
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    sopka[i] = pair<int, int>(x, y);
  }
  sopka.push_back(pair<int, int>(n, 0));
  m++;
  sort(sopka.begin(), sopka.end());
  sopka.push_back(pair<int, int>(1023456789, 1023456789));
  vector<pair<int, int> > canget(1, pair<int, int>(1, 2));
  int i = 0;
  int oldx = 0;
  while (i < m) {
    int x = sopka[i].first;
    vector<int> y(1, 0);
    for (; sopka[i].first == x; i++) y.push_back(sopka[i].second);
    y.push_back(1023456789);
    vector<pair<int, int> > ncanget;
    if (x > oldx + 1) {
      int miny;
      if (canget.size() == 0)
        miny = 1023456789;
      else
        miny = canget[0].first;
      canget = vector<pair<int, int> >(1, pair<int, int>(miny, 1023456789));
    }
    int zauj = 0;
    for (int j = 0; j < y.size() - 1; j++) {
      if (zauj >= canget.size()) break;
      bool out = 0;
      while (canget[zauj].second <= y[j] + 1) {
        zauj++;
        if (zauj >= canget.size()) {
          out = 1;
          break;
        }
      }
      if (out) break;
      int st = max(y[j] + 1, canget[zauj].first);
      if (st < y[j + 1]) {
        ncanget.push_back(pair<int, int>(st, y[j + 1]));
      }
    }
    canget = ncanget;
    if (x == n) {
      bool ok = 0;
      for (int i = 0; i < canget.size(); i++) {
        if (canget[i].first <= n && n < canget[i].second) ok = 1;
      }
      if (ok)
        printf("%d\n", (n - 1) * 2);
      else
        printf("-1\n");
    }
    oldx = x;
  }
  return 0;
}
