#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void umax(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
inline void umin(T &a, T b) {
  if (a > b) a = b;
}
template <class T>
inline T abs(T a) {
  return a > 0 ? a : -a;
}
template <class T>
inline T gcd(T a, T b) {
  return __gcd(a, b);
}
template <class T>
inline T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
const int inf = 1e9 + 143;
const long long longinf = 1e18 + 143;
inline int read() {
  int x;
  scanf(" %d", &x);
  return x;
}
const int N = 3e5 + 100;
int x[N], y[N];
set<pair<int, int> > goods;
vector<int> ps[N];
void cut(int x) {
  __typeof((goods).begin()) it = goods.upper_bound(pair<int, int>(x, inf));
  if (it != goods.begin() && goods.size()) {
    --it;
    int l = it->first;
    int r = it->second;
    goods.erase(it);
    if (l <= x - 1) goods.insert(pair<int, int>(l, x - 1));
    if (x + 1 <= r) goods.insert(pair<int, int>(x + 1, r));
  }
}
void extend(int l, int r) {
  __typeof((goods).begin()) it = goods.lower_bound(pair<int, int>(l, 0));
  if (it == goods.end() || it->first > r) return;
  int minx = it->first;
  while (it != goods.end() && it->first <= r) {
    __typeof((goods).begin()) nit = it;
    nit++;
    goods.erase(it);
    it = nit;
  }
  goods.insert(pair<int, int>(minx, r));
}
int main() {
  int n = read();
  int m = read();
  vector<int> ys;
  ys.push_back(1);
  ys.push_back(n);
  for (int i = 1; i <= m; i++) {
    x[i] = read();
    y[i] = read();
    ys.push_back(x[i]);
    if (x[i] > 1) ys.push_back(x[i] - 1);
    if (x[i] < n) ys.push_back(x[i] + 1);
  }
  sort((ys).begin(), (ys).end());
  ys.erase(unique((ys).begin(), (ys).end()), ys.end());
  for (int i = 1; i <= m; i++) {
    x[i] = lower_bound((ys).begin(), (ys).end(), x[i]) - ys.begin();
    ps[x[i]].push_back(y[i]);
  }
  if (ys.back() != n) {
    exit(123);
  }
  if (ys[0] != 1) exit(124);
  ps[0].push_back(n + 1);
  sort((ps[0]).begin(), (ps[0]).end());
  goods.insert(pair<int, int>(1, ps[0][0] - 1));
  for (int y = 1; y < ys.size(); y++) {
    ps[y].push_back(0);
    ps[y].push_back(n + 1);
    sort((ps[y]).begin(), (ps[y]).end());
    for (__typeof((goods).begin()) it = (goods).begin(); it != (goods).end();
         it++)
      0;
    0;
    for (int i = 1; i + 1 < ps[y].size(); i++) {
      cut(ps[y][i]);
    }
    for (int i = 0; i + 1 < ps[y].size(); i++) {
      if (ps[y][i] + 1 <= ps[y][i + 1] - 1)
        extend(ps[y][i] + 1, ps[y][i + 1] - 1);
    }
    for (__typeof((goods).begin()) it = (goods).begin(); it != (goods).end();
         it++)
      0;
    0;
  }
  if (goods.size() && goods.rbegin()->second == n) {
    printf("%d\n", n + n - 2);
  } else {
    puts("-1");
  }
  return 0;
}
