#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int vis[N];
map<int, map<int, int> > mp1, mp2;
queue<int> Q;
int x[N], y[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]);
    if (x[i] == 1 || y[i] == n) Q.push(i), vis[i] = 1;
    mp1[x[i]][y[i]] = i;
    mp2[y[i]][-x[i]] = i;
  }
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    int px = x[u], py = y[u];
    if (px == n || py == 1) return 0 * printf("-1\n");
    if (mp1.count(px + 1)) {
      map<int, int>::iterator it = mp1[px + 1].lower_bound(py - 1);
      if (it != mp1[px + 1].end() && !vis[it->second])
        Q.push(it->second), vis[it->second] = 1;
    }
    if (mp2.count(py - 1)) {
      map<int, int>::iterator it = mp2[py - 1].lower_bound(-(px + 1));
      if (it != mp2[py - 1].end() && !vis[it->second])
        Q.push(it->second), vis[it->second] = 1;
    }
  }
  return 0 * printf("%d\n", n * 2 - 2);
}
