#include <bits/stdc++.h>
using namespace std;
int n, m;
pair<int, int> p[100005];
vector<pair<int, int> > v[2];
vector<int> vt;
bool ok() {
  int now_p = 1, now = 0, last_first;
  v[now ^ 1].clear();
  if (p[now_p].first != 1) {
    v[now ^ 1].push_back(make_pair(1, n));
    last_first = 0;
  } else {
    v[now ^ 1].push_back(make_pair(1, p[now_p].second - 1));
    last_first = p[now_p].first;
    while (now_p <= m && p[now_p].first == last_first) ++now_p;
  }
  while (now_p <= m) {
    v[now].clear();
    if (p[now_p].first != last_first + 1) {
      int t = v[now ^ 1][0].first;
      v[now ^ 1].clear();
      v[now ^ 1].push_back(make_pair(t, n));
    }
    vt.clear();
    last_first = p[now_p].first;
    while (now_p <= m && p[now_p].first == last_first)
      vt.push_back(p[now_p++].second);
    int sz = (int)vt.size(), vt_id = 0, tl = 0;
    for (int i = 0; i < (int)v[now ^ 1].size(); ++i) {
      tl = max(tl, v[now ^ 1][i].first);
      while (tl <= v[now ^ 1][i].second) {
        while (vt_id < sz && vt[vt_id] < tl) {
          if (vt_id == sz - 1) v[now].push_back(make_pair(tl, n));
          ++vt_id;
        }
        if (vt_id >= sz) break;
        if (vt[vt_id] - 1 >= tl) v[now].push_back(make_pair(tl, vt[vt_id] - 1));
        tl = vt[vt_id] + 1;
        if (vt_id == sz - 1) {
          if (tl <= v[now ^ 1][i].second)
            v[now].push_back(make_pair(tl, n));
          else {
            while (i + 1 < v[now ^ 1].size() &&
                   v[now ^ 1][i + 1].second <= vt[vt_id])
              ++i;
            if (i + 1 == v[now ^ 1].size()) break;
            v[now].push_back(
                make_pair(max(v[now ^ 1][i + 1].first, vt[vt_id] + 1), n));
          }
        }
        vt_id++;
      }
    }
    if ((int)v[now].size() == 0) return false;
    now ^= 1;
  }
  if (last_first == n && v[now ^ 1].back().second != n) return false;
  return true;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) scanf("%d%d", &p[i].first, &p[i].second);
  sort(p + 1, p + 1 + m);
  if (ok())
    printf("%d\n", 2 * n - 2);
  else
    puts("-1");
  return 0;
}
