#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 2;
const long long INF = 1e9 + 2;
const long long MOD = 1e9 + 7;
string s;
int n, m, r, last = 1, j, k, f;
vector<pair<int, int> > vol, ans, ans2, ans3;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int l, r;
    scanf("%i%i", &l, &r);
    vol.push_back(make_pair(l, r));
  }
  sort(vol.begin(), vol.end());
  if (vol.size() == 0) return cout << 2 * n - 2, 0;
  int p = 0, fl = 0;
  for (int i = 0; i < vol.size() && vol[i].first == 1; i++) {
    if (vol[i].second == 1) return cout << -1, 0;
    if (!fl) {
      fl = 1;
      ans.push_back(make_pair(1, vol[i].second - 1));
    }
    p++;
  }
  if (!fl) ans.push_back(make_pair(1, n));
  fl = 1;
  int t = 1;
  for (int i = p; i < vol.size(); i++) {
    if (vol[i].first != r) {
      if (!fl) {
        if (r > t + 1 && ans.size() > 0) {
          int s = ans[0].first;
          ans.clear();
          ans.push_back(make_pair(s, n));
        }
        if (vol[i].first == n) f = 1;
        if (last <= n) ans2.push_back(make_pair(last, n));
        last = 1;
        for (j = 0, k = 0; j < ans.size() && k < ans2.size();) {
          int l = max(ans[j].first, last), r = ans2[k].first;
          if (ans[j].second < r) {
            j++;
            continue;
          }
          if (l > ans2[k].second) {
            k++;
            continue;
          }
          ans3.push_back(make_pair(max(l, r), ans2[k].second));
          last = ans2[k].second + 2;
          if (ans[j].second <= ans2[k].second || last > n) j++;
          k++;
        }
        ans2.clear();
        ans.clear();
        ans = ans3;
        ans3.clear();
        last = 1;
        t = r;
      } else
        fl = 0;
      r = vol[i].first;
    }
    if (vol[i].second == n && vol[i].first == n) return cout << -1, 0;
    if (last < vol[i].second)
      ans2.push_back(make_pair(last, vol[i].second - 1));
    last = vol[i].second + 1;
  }
  if (!fl) {
    if (r > (t + 1) && ans.size() > 0) {
      int s = ans[0].first;
      ans.clear();
      ans.push_back(make_pair(s, n));
    }
    if (last <= n) ans2.push_back(make_pair(last, n));
    last = 1;
    for (j = 0, k = 0; j < ans.size() && k < ans2.size();) {
      int l = max(ans[j].first, last), r = ans2[k].first;
      if (ans[j].second < r) {
        j++;
        continue;
      }
      if (l > ans2[k].second) {
        k++;
        continue;
      }
      ans3.push_back(make_pair(max(l, r), ans2[k].second));
      last = ans2[k].second + 2;
      if (ans[j].second <= ans2[k].second || last > n) j++;
      k++;
    }
    ans2.clear();
    ans.clear();
    ans = ans3;
    ans3.clear();
  }
  if (!f && ans.size() > 0) {
    int l = ans[0].first;
    ans.clear();
    ans.push_back(make_pair(l, n));
  }
  for (int i = 0; i < ans.size(); i++)
    if (n >= ans[i].first && n <= ans[i].second) return cout << 2 * n - 2, 0;
  cout << -1;
  return 0;
}
