#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = (int)1e9 + 7;
const int N = (int)1e5 + 7;
char read_char() {
  char c;
  for (;;) {
    c = getchar();
    if (c == '#' || c == '.') return c;
  }
}
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= MOD;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % MOD;
    a = a * a % MOD;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int add(int a, int b) {
  if ((a += b) >= MOD) a -= MOD;
  return a;
}
int mul(int a, int b) { return 1ll * a * b % MOD; }
int n, m, tot, id[N];
pair<int, int> a[N];
vector<pair<int, int> > cur, tmp, vol[N];
bool cross(pair<int, int> a, pair<int, int> b) {
  return a.second >= b.first && b.second >= a.first;
}
pair<int, int> work(pair<int, int> a, pair<int, int> b) {
  pair<int, int> ret;
  ret.first = max(a.first, b.first);
  ret.second = b.second;
  return ret;
}
void Init() {
  a[0].first = a[0].second = 0;
  a[m + 1].first = a[m + 1].second = n + 1;
  for (int i = (1); i < (m + 1); ++i) scanf("%d%d", &a[i].first, &a[i].second);
  sort(a, a + m + 1);
  tot = 0;
  for (int i = (1); i < (m + 1); ++i) {
    if (a[i].first != a[i - 1].first) {
      vol[++tot].push_back({1, a[i].second - 1});
      id[tot] = a[i].first;
    } else {
      vol[tot].push_back({a[i - 1].second + 1, a[i].second - 1});
    }
    if (a[i + 1].first != a[i].first) vol[tot].push_back({a[i].second + 1, n});
  }
}
int Solve() {
  int lay = 1;
  id[0] = 0;
  cur.push_back({1, 1});
  while (lay <= tot) {
    if (id[lay] > id[lay - 1] + 1) {
      int l = cur[0].first;
      cur.clear();
      cur.push_back({l, n});
    }
    tmp.clear();
    int pos = 0;
    for (int i = (0); i < ((int)(cur).size()); ++i)
      for (int j = (pos); j < ((int)(vol[lay]).size()); ++j) {
        if (vol[lay][j].first > vol[lay][j].second) continue;
        if (cross(cur[i], vol[lay][j])) {
          tmp.push_back(work(cur[i], vol[lay][j]));
        } else if (vol[lay][j].first > cur[i].second) {
          pos = j;
          break;
        }
      }
    if (tmp.empty()) return !puts("-1");
    swap(cur, tmp);
    lay++;
  }
  if (id[lay - 1] < n || cur[(int)(cur).size() - 1].second == n)
    return !printf("%d\n", 2 * n - 2);
  else
    return !puts("-1");
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    Init();
    Solve();
  }
  return 0;
}
