#include <bits/stdc++.h>
using namespace std;
int n, m, a, b, x;
vector<pair<int, int> > v;
bool canGo() {
  sort(v.begin(), v.end());
  if (v[m - 1] == make_pair(n, n)) return false;
  int row = 0, start, end;
  vector<pair<int, int> > range;
  range.push_back(make_pair(1, 1));
  for (int i = 0; i < m;) {
    if (v[i].first > row + 1) {
      start = range[0].first;
      end = n;
      range.clear();
      range.push_back(make_pair(start, end));
    }
    vector<pair<int, int> > newrange;
    if (range[0].first <= v[i].second - 1)
      newrange.push_back(make_pair(range[0].first, v[i].second - 1));
    row = v[i].first;
    int j = 0;
    while (i < m && v[i].first == row) {
      start = v[i].second + 1;
      if (i + 1 == m || v[i + 1].first != row)
        end = n;
      else
        end = v[i + 1].second - 1;
      i++;
      if (start > end) continue;
      while (j < range.size() && range[j].second < start) j++;
      if (j == range.size()) continue;
      if (range[j].first <= end)
        newrange.push_back(make_pair(max(start, range[j].first), end));
    }
    range = newrange;
    if (range.empty()) return false;
  }
  if (row != n) return range.size();
  return range.back().second == n;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    v.push_back(make_pair(a, b));
  }
  bool ok = canGo();
  if (ok)
    cout << n + n - 2 << endl;
  else
    cout << -1 << endl;
  return 0;
}
