#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T sqr(T x) {
  return x * x;
}
const double EPS = 1e-9;
const int MAXN = int(1e5) + 10;
int n, m;
vector<int> all_x;
vector<int> row_y[MAXN];
pair<int, int> pairs[MAXN];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < (int)m; i++) {
    scanf("%d%d", &pairs[i].first, &pairs[i].second);
    all_x.push_back(pairs[i].first);
  }
  all_x.push_back(1);
  pairs[m++] = make_pair(1, n + 1);
  all_x.push_back(n);
  pairs[m++] = make_pair(n, n + 1);
  sort(all_x.begin(), all_x.end());
  all_x.resize(unique(all_x.begin(), all_x.end()) - all_x.begin());
  for (int i = 0; i < (int)m; i++) {
    int x = pairs[i].first;
    int pos = lower_bound(all_x.begin(), all_x.end(), x) - all_x.begin();
    row_y[pos].push_back(pairs[i].second);
  }
  for (int i = 0; i < (int)((int)(all_x).size()); i++)
    sort(row_y[i].begin(), row_y[i].end());
  vector<pair<int, int> > bounds;
  if (all_x[0] == 1) {
    bounds.push_back(make_pair(1, row_y[0][0] - 1));
  } else {
    bounds.push_back(make_pair(1, n));
  }
  for (int i = 0; i < (int)((int)(all_x).size()) - 1; i++) {
    if (all_x[i + 1] > all_x[i] + 1 && !bounds.empty()) {
      bounds[((int)(bounds).size()) - 1].second = n;
    }
    vector<pair<int, int> > new_bounds;
    for (int j = 0; j < (int)((int)(bounds).size()); j++) {
      int l = bounds[j].first;
      int r = bounds[j].second;
      int pos = lower_bound(row_y[i + 1].begin(), row_y[i + 1].end(), l) -
                row_y[i + 1].begin();
      int last = l - 1;
      for (int k = pos;
           k < ((int)(row_y[i + 1]).size()) && row_y[i + 1][k] <= r; k++) {
        int y = row_y[i + 1][k];
        if (last < y - 1) new_bounds.push_back(make_pair(last + 1, y - 1));
        last = y;
      }
      if (last < r) {
        pos = upper_bound(row_y[i + 1].begin(), row_y[i + 1].end(), r) -
              row_y[i + 1].begin();
        new_bounds.push_back(make_pair(
            last + 1,
            pos == ((int)(row_y[i + 1]).size()) ? n : (row_y[i + 1][pos] - 1)));
      }
    }
    bounds.clear();
    int l = 1;
    int r = -1;
    for (int j = 0; j < (int)((int)(new_bounds).size()); j++) {
      int L = new_bounds[j].first;
      int R = new_bounds[j].second;
      if (max(l, L) > min(r, R)) {
        if (l <= r) bounds.push_back(make_pair(l, r));
        l = L;
        r = R;
        continue;
      }
      l = min(l, L);
      r = max(r, R);
    }
    if (l <= r) bounds.push_back(make_pair(l, r));
  }
  printf("%d\n",
         (!bounds.empty() && bounds[((int)(bounds).size()) - 1].second == n)
             ? (2 * n - 2)
             : (-1));
  return 0;
}
