#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void checkMin(T &a, T b) {
  if (b < a) a = b;
}
template <typename T>
inline void checkMax(T &a, T b) {
  if (a < b) a = b;
}
int n, m, x, y;
map<int, set<int>> row, col;
queue<pair<int, int>> q;
inline void relax_col(int x, int y) {
  if (!col.count(y)) return;
  auto iter = col[y].upper_bound(x);
  if (iter == col[y].begin()) return;
  --iter;
  while (true) {
    q.push(make_pair(*iter, y));
    if (iter == col[y].begin()) {
      col[y].erase(iter);
      break;
    }
    auto jter = iter;
    --jter;
    if (row.count(*iter)) row[*iter].erase(y);
    col[y].erase(iter);
    iter = jter;
  }
  if (col[y].empty()) col.erase(y);
}
inline void relax_row(int x, int y) {
  if (!row.count(x)) return;
  auto iter = row[x].lower_bound(y);
  for (; iter != row[x].end(); iter = row[x].erase(iter)) {
    q.push(make_pair(x, *iter));
    if (col.count(*iter)) col[*iter].erase(x);
  }
  if (row[x].empty()) row.erase(x);
}
bool check() {
  for (int i = 0; i < int(m); ++i) {
    scanf("%d%d", &x, &y);
    if (x == 1 || y == n) {
      q.push(make_pair(x, y));
    } else {
      row[x].insert(y);
      col[y].insert(x);
    }
  }
  while (!q.empty()) {
    int x = q.front().first, y = q.front().second;
    if (x == n || y == 1) return false;
    q.pop();
    relax_row(x + 1, y - 1);
    relax_col(x + 1, y - 1);
  }
  return true;
}
int main() {
  scanf("%d%d", &n, &m);
  cout << (check() ? 2LL * (n - 1) : -1) << "\n";
  return 0;
}
