#include <bits/stdc++.h>
using namespace std;
int n, k;
int x[100005];
pair<int, int> a[100005];
set<pair<int, int> > S1, S2;
vector<int> E[100005];
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= k; ++i) {
    scanf("%d %d", &a[i].first, &a[i].second);
    x[++x[0]] = a[i].first;
  }
  x[++x[0]] = n;
  sort(x + 1, x + x[0] + 1);
  x[0] = unique(x + 1, x + x[0] + 1) - x - 1;
  for (int i = 1; i <= k; ++i) {
    E[lower_bound(x + 1, x + x[0] + 1, a[i].first) - x].push_back(a[i].second);
  }
  for (int i = 1; i <= x[0]; ++i) {
    sort(E[i].begin(), E[i].end());
  }
  S1.insert(make_pair(1, 1));
  int sol = 0;
  for (int i = 1; i <= x[0]; ++i) {
    if (S1.empty()) {
      sol = -1;
      break;
    }
    if (x[i] != (i == 1 ? 1 : x[i - 1] + 1)) {
      int capat = (*(S1.begin())).first;
      S1.clear();
      S1.insert(make_pair(capat, n));
    }
    for (int j = 0; j < (int)E[i].size(); ++j) {
      int split = E[i][j];
      set<pair<int, int> >::iterator itt =
          S1.upper_bound(make_pair(split, n + 5));
      if (itt == S1.begin()) continue;
      --itt;
      int st = itt->first, dr = itt->second;
      if (dr >= split) {
        S1.erase(itt);
        if (split > st) {
          S1.insert(make_pair(st, split - 1));
        }
        if (split < dr) {
          S1.insert(make_pair(split + 1, dr));
        }
      }
    }
    E[i].push_back(n + 1);
    set<pair<int, int> >::iterator itt = S1.begin();
    for (int j = 0; j < (int)E[i].size(); ++j) {
      int capat = -1, split = E[i][j];
      if (itt != S1.end() && itt->second < split) {
        capat = itt->first;
      }
      while (itt != S1.end() && itt->second < split) {
        ++itt;
      }
      if (capat != -1) {
        S2.insert(make_pair(capat, split - 1));
      }
    }
    S1 = S2;
    S2.clear();
  }
  if (S1.empty())
    sol = -1;
  else {
    set<pair<int, int> >::iterator itt = S1.end();
    --itt;
    if (itt->second < n) {
      sol = -1;
    }
  }
  if (sol != -1) sol = n + n - 2;
  printf("%d\n", sol);
  return 0;
}
