#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int b[N], tot, x[N], y[N];
vector<int> V[N];
pair<int, int> res[N], cur[N];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &x[i], &y[i]);
    b[++tot] = x[i];
  }
  sort(b + 1, b + tot + 1);
  int mm = unique(b + 1, b + tot + 1) - b - 1;
  for (int i = 1; i <= m; i++) {
    int pos = lower_bound(b + 1, b + mm + 1, x[i]) - b;
    V[pos].push_back(y[i]);
  }
  int cnt = 0;
  for (int i = 1; i <= mm; i++) sort(V[i].begin(), V[i].end());
  cnt = 1;
  res[0] = make_pair(1, 1);
  for (int i = 1; i <= mm; i++) {
    if (b[i] > b[i - 1] + 1) {
      cnt = 1;
      int x = res[0].first;
      res[0] = make_pair(x, n);
    }
    int c = 0, siz = V[i].size(), pos = 0;
    for (int j = 0; j < siz; j++) {
      if (V[i][j] > pos + 1) cur[c] = make_pair(pos + 1, V[i][j] - 1), c++;
      pos = V[i][j];
    }
    if (pos < n) cur[c] = make_pair(pos + 1, n), c++;
    int now = 0;
    for (int j = 0; j < cnt; j++) {
      while (now < c && cur[now].first <= res[j].second) {
        if (cur[now].second >= res[j].first) {
          cur[now].first = max(cur[now].first, res[j].first);
        } else
          cur[now] = make_pair(-1, -1);
        now++;
      }
    }
    cnt = 0;
    for (int j = 0; j < now; j++)
      if (cur[j].first != -1) res[cnt] = cur[j], cnt++;
    if (cnt == 0) return puts("-1");
  }
  bool ok = true;
  if (b[mm] != n)
    ok = true;
  else if (res[cnt - 1].second == n)
    ok = true;
  else
    ok = false;
  printf("%d\n", ok ? 2 * n - 2 : -1);
  return 0;
}
