#include <bits/stdc++.h>
template <typename T>
void read(T& val) {
  std::string tmp = typeid(val).name();
  if (strcmp(tmp.c_str(), "i") == 0)
    scanf("%d", &val);
  else if (strcmp(tmp.c_str(), "x") == 0)
    scanf("%I64d", &val);
  else if (strcmp(tmp.c_str(), "d") == 0)
    scanf("%lf", &val);
  else if (tmp.length() > 2 && tmp.back() == 'c')
    scanf("%s", val);
  else if (strcmp(tmp.c_str(), "c") == 0)
    scanf("%c", &val);
}
template <typename T, typename... Targs>
void read(T& val, Targs&... Fargs) {
  read(val);
  read(Fargs...);
}
template <typename T>
void print(T val) {
  std::string tmp = typeid(val).name();
  if (strcmp(tmp.c_str(), "i") == 0)
    printf("%d", val);
  else if (strcmp(tmp.c_str(), "x") == 0)
    printf("%I64d", val);
  else if (strcmp(tmp.c_str(), "d") == 0)
    printf("%.15f", val);
  else if (strcmp(tmp.c_str(), "c") == 0)
    printf("%c", val);
  else if (tmp.length() > 2 && tmp.back() == 'c')
    printf("%s", val);
}
template <typename T, typename... Targs>
void print(T val, Targs... Fargs) {
  print(val);
  print(Fargs...);
}
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e6 + 5;
const double eps = 1e-9;
using namespace std;
pair<int, int> p[MAXN];
vector<pair<int, int> > a, na;
int main() {
  int n, m;
  read(n, m);
  for (int i = 0; i < m; i++) {
    int x, y;
    read(x, y);
    p[i] = {x, y};
  }
  sort(p, p + m);
  a.push_back({1, 1});
  int cur = 0, nx = 0, nc = 0;
  int st, en, id;
  while (cur < m) {
    if (!a.empty() && p[cur].first != nx + 1) {
      st = a[0].first;
      a.clear();
      a.push_back({st, n});
    }
    for (nc = cur; p[nc].first == p[cur].first; nc++)
      ;
    st = 1, id = 0, na.clear();
    for (int i = cur; i <= nc; i++) {
      en = i < nc ? p[i].second - 1 : n;
      for (; id < a.size() && a[id].second < st; id++)
        ;
      if (id < a.size() && max(a[id].first, st) <= en)
        na.push_back({max(a[id].first, st), en});
      st = en + 2;
    }
    a = na, nx = p[cur].first, cur = nc;
  }
  print((!a.empty() && (nx < n || a.back().second == n)) ? n * 2 - 2 : -1);
  return 0;
}
