#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const int nn = 100005;
int main(int argc, char* rgv[]) {
  int n, m;
  scanf("%d%d", &n, &m);
  map<int, vector<int>> s;
  map<int, int> t;
  t[1] = 1;
  for (int i = 1; i <= m; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    s[x].push_back(y);
  }
  int c = 0;
  for (auto p : s) {
    int x = p.first;
    if (x > c + 1) {
      int u = t.begin()->first;
      t.clear();
      t[u] = n;
    }
    for (int y : p.second) {
      auto it = t.upper_bound(y);
      if (it != t.begin()) {
        --it;
        if (it->second >= y) {
          int u = it->first, v = it->second;
          t.erase(it);
          if (u < y) t[u] = y - 1;
          if (y < v) t[y + 1] = v;
        }
      }
    }
    if (t.empty()) {
      puts("-1");
      return 0;
    }
    int a = t.rbegin()->second;
    int mn = n + 1;
    for (int y : p.second)
      if (y > a) mn = mn < y ? mn : y;
    t[t.rbegin()->first] = mn - 1;
    c = x;
  }
  int ans = -1;
  if (c < n)
    ans = 2 * n - 2;
  else
    ans = (t.rbegin()->second == n ? 2 * n - 2 : -1);
  printf("%d\n", ans);
  return 0;
}
