#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
int n, m, x[N], y[N], v[N];
map<int, map<int, int> > m1, m2;
queue<int> q;
map<int, int>::iterator it;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x[i], &y[i]);
    if (x[i] == 1 or y[i] == n) {
      v[i] = 1;
      q.push(i);
    }
    m1[x[i]][y[i]] = i;
    m2[y[i]][-x[i]] = i;
  }
  while (!q.empty()) {
    int id = q.front();
    q.pop();
    if (x[id] == n or y[id] == 1) {
      puts("-1");
      return 0;
    }
    if (m1.count(x[id] + 1)) {
      it = m1[x[id] + 1].lower_bound(y[id] - 1);
      if (it != m1[x[id] + 1].end() and v[it->second] == 0) {
        v[it->second] = 1;
        q.push(it->second);
      }
    }
    if (m2.count(y[id] - 1)) {
      it = m2[y[id] - 1].lower_bound(-x[id] - 1);
      if (it != m2[y[id] - 1].end() and v[it->second] == 0) {
        v[it->second] = 1;
        q.push(it->second);
      }
    }
  }
  printf("%d\n", n + n - 2);
  return 0;
}
