#include <bits/stdc++.h>
using namespace std;
int N, M;
map<int, vector<int> > base;
bool OK = false;
vector<pair<int, int> > load(vector<int>& w) {
  vector<pair<int, int> > use;
  sort(w.begin(), w.end());
  int lu = 0;
  for (int i = 0; i < ((int)(w).size()); ++i) {
    if (lu + 1 != w[i]) use.push_back(make_pair(lu + 1, w[i] - 1));
    lu = w[i];
  }
  if (lu != N) use.push_back(make_pair(lu + 1, N));
  return use;
}
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 0; i < M; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    base[x].push_back(y);
    if (x + 1 <= N) base[x + 1];
  }
  set<pair<int, int> > cline, nline;
  if (!base.count(1))
    cline.insert(make_pair(1, N));
  else {
    sort(base[1].begin(), base[1].end());
    cline.insert(make_pair(1, base[1][0]));
  }
  for (map<int, vector<int> >::iterator it = base.begin(); it != base.end();
       ++it) {
    nline.clear();
    vector<pair<int, int> > use = load(it->second);
    for (int i = 0; i < ((int)(use).size()); ++i) {
      if (cline.empty()) break;
      pair<int, int> t = *cline.begin();
      if (t.second < use[i].first) {
        cline.erase(t);
        --i;
        continue;
      }
      if (t.first > use[i].second) continue;
      int lp = max(t.first, use[i].first);
      int rp = use[i].second;
      if (lp <= rp) nline.insert(make_pair(lp, rp));
    }
    cline.swap(nline);
  }
  for (set<pair<int, int> >::iterator it = cline.begin(); it != cline.end();
       ++it)
    if (it->first <= N && N <= it->second) OK = true;
  if (!OK)
    puts("-1");
  else
    printf("%d\n", 2 * (N - 1));
  return 0;
}
