#include <bits/stdc++.h>
using namespace std;
vector<int> row;
vector<pair<int, int> > v;
vector<int> mount[200005];
vector<pair<int, int> > range[200005];
map<int, int> mapa;
int search(int l, int r, int idx, int val) {
  int best = -1;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (range[idx][mid].second >= val) {
      best = range[idx][mid].first;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  return best;
}
int main(void) {
  int n, m;
  int x, y;
  scanf(" %d %d", &n, &m);
  row.push_back(1);
  row.push_back(n);
  for (int i = 0; i < m; i++) {
    scanf(" %d %d", &x, &y);
    row.push_back(x);
    v.push_back(make_pair(x, y));
  }
  sort(row.begin(), row.end());
  int next = 0;
  for (int i = 0; i < (int)row.size(); i++) {
    x = row[i];
    if (mapa.find(x) == mapa.end()) {
      mapa[x] = next++;
    }
    if (mapa.find(x + 1) == mapa.end()) {
      mapa[x + 1] = next++;
    }
  }
  for (int i = 0; i < (int)v.size(); i++) {
    x = v[i].first;
    y = v[i].second;
    mount[mapa[x]].push_back(y);
  }
  for (int i = 0; i < next; i++) {
    mount[i].push_back(0);
    mount[i].push_back(n + 1);
    sort(mount[i].begin(), mount[i].end());
  }
  range[0].push_back(make_pair(1, mount[0][1] - 1));
  for (int i = 1; i < next; i++) {
    vector<pair<int, int> > aux;
    for (int j = 1; j < (int)mount[i].size(); j++) {
      int l = mount[i][j - 1] + 1;
      int r = mount[i][j] - 1;
      if (l <= r) {
        aux.push_back(make_pair(l, r));
      }
    }
    for (int j = 0; j < (int)aux.size(); j++) {
      int idx = search(0, (int)range[i - 1].size() - 1, i - 1, aux[j].first);
      int a = max(idx, aux[j].first);
      int b = aux[j].second;
      if (idx != -1 && a <= b) {
        range[i].push_back(make_pair(a, b));
      }
    }
  }
  int ok = 0;
  int last = mapa[n];
  for (int i = 0; i < (int)range[last].size(); i++) {
    int a = range[last][i].first;
    int b = range[last][i].second;
    if (a <= n && n <= b) {
      ok = 1;
    }
  }
  if (ok) {
    printf("%d\n", n + n - 2);
  } else {
    printf("-1\n");
  }
  return 0;
}
