#include <bits/stdc++.h>
using namespace std;
struct data {
  int s, e, min;
  data() {}
  data(int _s, int _e) : s(_s), e(_e), min(1000000001) {}
};
map<int, int> id;
vector<int> coord;
int n, m, N;
int X[100005], Y[100005];
vector<int> layer[100005];
vector<data> node[100005];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i)
    scanf("%d%d", X + i, Y + i), coord.push_back(Y[i]);
  coord.push_back(1), coord.push_back(n);
  sort(coord.begin(), coord.end());
  coord.erase(unique(coord.begin(), coord.end()), coord.end());
  N = coord.size();
  for (int i = 0; i < N; ++i) id[coord[i]] = i;
  for (int i = 0; i < m; ++i) layer[id[Y[i]]].push_back(X[i]);
  for (int i = 0; i < N; ++i) {
    layer[i].push_back(0);
    layer[i].push_back(n + 1);
    sort(layer[i].begin(), layer[i].end());
    for (int j = 0; j + 1 < layer[i].size(); ++j) {
      if (layer[i][j] + 1 <= layer[i][j + 1] - 1)
        node[i].push_back(data(layer[i][j] + 1, layer[i][j + 1] - 1));
    }
  }
  node[0][0].min = 1;
  for (int i = 0; i < N - 1; ++i) {
    vector<data> &cur = node[i], &nxt = node[i + 1];
    int k = 0;
    for (int j = 0; j < cur.size(); ++j) {
      if (cur[j].min > cur[j].e) continue;
      if (coord[i] + 1 != coord[i + 1]) {
        while (k < nxt.size() && nxt[k].e < cur[j].min) k++;
        while (k < nxt.size()) nxt[k].min = max(cur[j].min, nxt[k].s), k++;
      } else {
        while (k < nxt.size() && nxt[k].s <= cur[j].e) {
          if (max(cur[j].min, nxt[k].s) <= min(cur[j].e, nxt[k].e)) {
            nxt[k].min = max(cur[j].min, nxt[k].s);
          }
          k++;
        }
      }
    }
  }
  bool ok = 0;
  for (int i = 0; i < node[N - 1].size(); ++i) {
    if (node[N - 1][i].e == n && node[N - 1][i].min <= n) ok = 1;
  }
  if (ok)
    cout << 2 * n - 2;
  else
    cout << -1;
}
