#include <bits/stdc++.h>
using namespace std;
const int maxM = 100 * 1001;
vector<pair<int, int> > rs, rs2;
pair<int, int> w[maxM];
vector<int> y;
int n, m;
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> w[i].first >> w[i].second;
  sort(w, w + m);
  int x = 1, lastx = 0, ind = 0, mn = 1;
  rs.push_back(make_pair(1, w[0].second - 1));
  for (int j = 0; j < m; j++) {
    y.clear();
    rs2.clear();
    x = w[j].first;
    if (x != lastx + 1) {
      rs.clear();
      rs.push_back(make_pair(mn, n));
    }
    lastx = x;
    for (; j < m && w[j].first == x; j++) y.push_back(w[j].second);
    j--;
    y.push_back(n + 1);
    ind = 0;
    for (int i = 0; i < rs.size(); i++) {
      bool fl = 0;
      while (y.size() > ind && y[ind] < rs[i].first) ind++, fl = 1;
      while (y.size() > ind && y[ind] <= rs[i].second) {
        rs2.push_back(make_pair(rs[i].first, y[ind] - 1));
        rs[i].first = y[ind] + 1;
        ind++;
        fl = 1;
      }
      if (!fl) rs2.push_back(make_pair(rs[i].first, y[ind] - 1));
      if (fl && y[ind - 1] < rs[i].second)
        rs2.push_back(make_pair(rs[i].first, y[ind] - 1));
      rs2.push_back(rs[i]);
    }
    if (y[y.size() - 2] < rs.back().second)
      rs2.push_back(make_pair(y[y.size() - 2] + 1, n));
    rs.clear();
    sort(rs2.begin(), rs2.end());
    for (int k = 1; k < rs2.size(); k++)
      if (rs2[k - 1].second >= rs2[k].first) {
        rs2[k].first = rs2[k - 1].first;
        rs2[k - 1].second = -1;
      }
    for (int k = 0; k < rs2.size(); k++)
      if (rs2[k].first <= rs2[k].second) rs.push_back(rs2[k]);
    if (rs.empty() || (x == n && rs.size() && rs.back().second != n)) {
      cout << -1 << endl;
      return 0;
    }
    mn = max(mn, rs[0].first);
  }
  cout << 2 * n - 2 << endl;
}
