#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 5;
pair<int, int> v[maxN];
int n, m;
bool cmp(pair<int, int> a, pair<int, int> b) {
  return a.first != b.first ? a.first < b.first : a.second < b.second;
}
int main() {
  ios_base::sync_with_stdio(false);
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &v[i].first, &v[i].second);
    if (v[i].first == n && v[i].second == n) {
      cout << -1;
      return 0;
    }
  }
  sort(v + 1, v + m + 1, cmp);
  vector<pair<int, int> > pre;
  pre.push_back(pair<int, int>(1, n));
  for (int i = 1; i <= m;) {
    if ((int)pre.size() == 0) {
      cout << -1;
      return 0;
    }
    if (i == 1 && v[i].first == 1) {
      pre.clear();
      int gt = 1e9 + 7;
      while (v[i].first == 1) gt = min(gt, v[i].second), ++i;
      if (gt - 1 >= 1) pre.push_back(pair<int, int>(1, gt - 1));
    }
    if (i != 1 && v[i - 1].first < v[i].first - 1) {
      int u = pre[0].first;
      pre.clear();
      pre.push_back(pair<int, int>(u, n));
    }
    vector<pair<int, int> > now;
    int j = 1;
    while (i <= m && v[i + 1].first == v[i].first) {
      if (v[i].second - 1 >= j)
        now.push_back(pair<int, int>(j, v[i].second - 1));
      j = v[i].second + 1;
      ++i;
    }
    if (v[i].second - 1 >= j) now.push_back(pair<int, int>(j, v[i].second - 1));
    if (v[i].second != n) now.push_back(pair<int, int>(v[i].second + 1, n));
    int c1 = 0;
    vector<pair<int, int> > pre2;
    for (int c2 = 0; c2 < (int)now.size(); ++c2) {
      while (c1 < (int)pre.size() && pre[c1].second < now[c2].first) ++c1;
      if (c1 < (int)pre.size() && pre[c1].first <= now[c2].second)
        pre2.push_back(
            pair<int, int>(max(pre[c1].first, now[c2].first), now[c2].second));
    }
    pre = pre2;
    ++i;
  }
  if ((int)pre.size() == 0) {
    cout << -1;
    return 0;
  }
  if (v[m].first == n) {
    bool ok = true;
    for (int i = 0; i < (int)pre.size(); ++i)
      if (pre[i].second == n) ok = false;
    if (ok) {
      cout << -1;
      return 0;
    }
  }
  cout << (long long)2 * n - 2;
  return 0;
}
