#include <bits/stdc++.h>
using namespace std;
pair<int, int> x[100100];
pair<int, int> del[100100];
pair<int, int> add[100100];
map<int, vector<int> > p;
map<int, vector<int> >::iterator mpt;
int main() {
  int n, m;
  cin >> n >> m;
  set<pair<int, int> > st;
  set<pair<int, int> >::iterator it;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &x[i].first, &x[i].second);
    p[x[i].first].push_back(x[i].second);
  }
  sort(x, x + m);
  int i;
  int mn = 1e9 + 5;
  for (i = 0; i < m; i++) {
    if (x[i].first != 1) break;
    mn = min(mn, x[i].second);
  }
  if (mn <= n) st.insert(make_pair(mn, n));
  int pr = 1;
  int en = 1;
  for (mpt = p.begin(); mpt != p.end(); mpt++) {
    en = mpt->first;
    int k = 0, k1 = 0;
    sort((mpt->second).begin(), (mpt->second).end());
    if (mpt->first == 1) continue;
    if (!st.empty() && st.begin()->first == 1 && st.begin()->second == n) {
      cout << -1;
      return 0;
    }
    if (pr != mpt->first - 1) {
      set<pair<int, int> >::iterator it1;
      for (it = st.begin(); it != st.end();) {
        it1 = it;
        it1++;
        del[k1++] = *it;
        if (it->first == 1) add[k++] = *it;
        it = it1;
      }
      for (int i = 0; i < (mpt->second).size(); i++) {
        add[k++] = (make_pair((mpt->second)[i], (mpt->second)[i]));
      }
    } else {
      int i = 0;
      for (it = st.begin(); it != st.end(); it++) {
        while (i < (mpt->second).size() && (mpt->second)[i] < (it->first) - 1) {
          add[k++] = make_pair((mpt->second)[i], (mpt->second)[i]);
          i++;
        }
        del[k1++] = *it;
        int i1 = n + 1;
        if (i < (mpt->second).size()) i1 = (mpt->second)[i];
        while (i < (mpt->second).size() && (mpt->second)[i] <= (it->second)) {
          i++;
        }
        if (it->first != 1) {
          if (i1 <= (it->second)) add[k++] = make_pair(i1, it->second);
        } else {
          add[k++] = *it;
        }
      }
      while (i < (mpt->second).size()) {
        add[k++] = make_pair((mpt->second)[i], (mpt->second)[i]);
        i++;
      }
    }
    for (int i = 0; i < k1; i++) {
      st.erase(del[i]);
    }
    pair<int, int> pr1 = add[0];
    for (int i = 0; i < k; i++) {
      if (pr1.second + 1 < add[i].first) {
        st.insert(pr1);
        pr1 = add[i];
      } else
        pr1.second = add[i].second;
    }
    if (k) st.insert(pr1);
    pr = mpt->first;
  }
  if (!st.empty() && st.begin()->first == 1 && st.begin()->second == n) {
    cout << -1;
    return 0;
  }
  if (st.empty() || en != n) {
    long long r = n - 1;
    r *= 2;
    cout << r << endl;
    return 0;
  }
  it = st.end();
  it--;
  if (it->second >= n) {
    cout << -1;
    return 0;
  }
  long long r = n - 1;
  r *= 2;
  cout << r << endl;
  return 0;
}
