#include <bits/stdc++.h>
using namespace std;
map<int, vector<int> > ma;
map<int, int> last, pre, cur, temp;
int dole() {
  temp.clear();
  for (map<int, int>::iterator it = pre.begin(); it != pre.end(); it++) {
    int x = it->first, y = it->second;
    map<int, int>::iterator i = last.upper_bound(y - 1);
    if (i == last.end()) {
      continue;
    }
    if (i->second >= y && i->second <= x)
      temp[x] = i->second;
    else if (i->second < y) {
      temp[x] = y;
      continue;
    }
  }
  swap(pre, temp);
  return 0;
}
int dol() {
  temp.clear();
  for (map<int, int>::iterator it = cur.begin(); it != cur.end(); it++) {
    int x = it->first, y = it->second;
    map<int, int>::iterator i = last.upper_bound(y - 1);
    if (i == last.end()) {
      continue;
    }
    if (i->second >= y && i->second <= x)
      temp[x] = i->second;
    else if (i->second < y) {
      temp[x] = y;
      continue;
    }
  }
  swap(last, temp);
  return 0;
}
int n;
int make(int r, int z) {
  if (z == 0) {
    if (r == 1) {
      pre.clear();
      int x = ma[1][0];
      pre[x - 1] = 1;
    }
    return 0;
  }
  if (z + 1 == r) {
    dole();
    return 0;
  }
  cur.clear();
  cur[n] = 1;
  dol();
  dole();
}
int solve() {
  map<int, vector<int> >::iterator it = ma.begin();
  int u = 0, r;
  while (it != ma.end()) {
    pre.clear();
    r = it->first;
    ma[r].push_back(n + 1);
    sort(ma[r].begin(), ma[r].end());
    int si = ma[r].size(), first = 1;
    for (int i = 0; i < si; i++) {
      int t = ma[r][i];
      if (first <= t - 1) {
        pre[t - 1] = first;
      }
      first = t + 1;
    }
    make(r, u);
    u = r;
    swap(pre, last);
    it++;
  }
  if (r != n) {
    if (last.size() != 0) return 1;
  }
  if (last.find(n) != last.end()) return 1;
  return 0;
}
int main() {
  int m, x, y;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    ma[x].push_back(y);
  }
  if (solve() == 1)
    cout << 2 * n - 2 << endl;
  else
    cout << -1 << endl;
  return 0;
}
