#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const double eps = 1e-9;
int N, M;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> N >> M;
  int result = (N - 1) * 2;
  map<int, int> curr, pred;
  map<int, set<int>> volc;
  for (int m = (0); m < (M); m++) {
    int X, Y;
    cin >> X >> Y;
    volc[Y].insert(X);
  }
  curr[1] = N + 1;
  if (((volc).find(1) != (volc).end())) {
    curr[1] = *volc[1].begin();
    volc.erase(1);
  }
  int p = 1;
  for (const auto &vo : volc) {
    swap(curr, pred);
    curr.clear();
    if (p < vo.first - 1) {
      int x = pred.begin()->first;
      pred.clear();
      pred[x] = N + 1;
    }
    auto ip = pred.begin();
    auto iv = vo.second.begin();
    while (ip != pred.end() && iv != vo.second.end()) {
      if (*iv < ip->first) {
        iv++;
        continue;
      }
      if (*iv >= ip->second) {
        curr[ip->first] = *iv;
        ip++;
        continue;
      }
      if (*iv > ip->first) {
        curr[ip->first] = *iv;
      }
      if (*iv < ip->second - 1) {
        pred[(*iv) + 1] = ip->second;
        ip = pred.erase(ip);
      } else {
        ip++;
      }
      iv++;
    }
    if (ip != pred.end()) {
      curr[ip->first] = N + 1;
    }
    while (!curr.empty() && curr.rbegin()->first > N) {
      curr.erase(prev(curr.rbegin().base()));
    }
    while (!curr.empty() && curr.begin()->second == 1) {
      curr.erase(curr.begin());
    }
    if (curr.empty()) {
      result = -1;
      break;
    }
    auto it = curr.begin();
    while (next(it) != curr.end()) {
      if (it->second >= next(it)->first) {
        it->second = next(it)->second;
        curr.erase(next(it));
      } else {
        it++;
      }
    }
    p = vo.first;
  }
  if (result != -1 && p == N && curr.rbegin()->second != N + 1) {
    result = -1;
  }
  cout << result << endl;
}
