#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
long long comb(long long n, long long r) {
  if (r < 0 || r > n) return 0;
  if ((n - r) < r) r = n - r;
  long long vec = 1;
  for (long long i = n; i > n - r; --i) {
    vec = vec * i;
  }
  for (long long i = 1; i < r + 1; ++i) {
    vec = vec / i;
  }
  return vec;
}
template <typename T>
void press(T &v) {
  v.erase(unique(v.begin(), v.end()), v.end());
}
long long small(vector<long long> &vec, long long first) {
  return lower_bound(vec.begin(), vec.end(), first) - vec.begin();
}
long long osmall(vector<long long> &vec, long long first) {
  return upper_bound(vec.begin(), vec.end(), first) - vec.begin();
}
long long big(vector<long long> &vec, long long first) {
  return vec.size() - osmall(vec, first);
}
long long obig(vector<long long> &vec, long long first) {
  return vec.size() - small(vec, first);
}
long long freq(vector<long long> &vec, long long first) {
  return upper_bound(vec.begin(), vec.end(), first) -
         lower_bound(vec.begin(), vec.end(), first);
}
long long maxa(vector<long long> &vec) {
  return max_element(vec.begin(), vec.end()) - vec.begin();
}
long long mina(vector<long long> &vec) {
  return min_element(vec.begin(), vec.end()) - vec.begin();
}
long long Set(long long qq, long long pos) { return (qq | (1 << pos)); }
long long chk(long long qq, long long pos) { return (qq & (1 << pos)); }
long long bits(long long qq) { return __builtin_popcount(qq); }
long long p2[32];
long long modpow(long long first, long long n, long long m) {
  if (n == 0) return 1 % m;
  long long u = modpow(first, n / 2, m);
  u = (u * u) % m;
  if (n % 2 == 1) u = (u * first) % m;
  return u;
}
long long _pow(long long vec, long long b) {
  if (!b) return 1;
  long long temp = _pow(vec, b / 2);
  temp = (temp * temp);
  if (b % 2) return (vec * temp);
  return temp;
}
long long cl(long long vec, long long b) {
  if (vec % b) return 1 + vec / b;
  return vec / b;
}
long long dx[] = {0, 0, -1, 1, 1, 1, -1, -1};
long long dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
const long long MOD = 1e9 + 7;
const long long inf = 1e18;
const long long N = 1e6 + 5;
const long long K = 1e3 + 10;
vector<pair<long long, long long> > rs, rs2;
pair<long long, long long> w[N];
vector<long long> second;
long long n, m;
void solve() {
  cin >> n >> m;
  for (long long i = 0; i < m; i++) cin >> w[i].first >> w[i].second;
  sort(w, w + m);
  long long first = 1, lastx = 0, ind = 0, mn = 1;
  rs.push_back(make_pair(1, w[0].second - 1));
  for (long long j = 0; j < m; j++) {
    second.clear();
    rs2.clear();
    first = w[j].first;
    if (first != lastx + 1) {
      rs.clear();
      rs.push_back(make_pair(mn, n));
    }
    lastx = first;
    for (; j < m && w[j].first == first; j++) second.push_back(w[j].second);
    j--;
    second.push_back(n + 1);
    ind = 0;
    for (long long i = 0; i < rs.size(); i++) {
      bool fl = 0;
      while (second.size() > ind && second[ind] < rs[i].first) ind++, fl = 1;
      while (second.size() > ind && second[ind] <= rs[i].second) {
        rs2.push_back(make_pair(rs[i].first, second[ind] - 1));
        rs[i].first = second[ind] + 1;
        ind++;
        fl = 1;
      }
      if (!fl) rs2.push_back(make_pair(rs[i].first, second[ind] - 1));
      if (fl && second[ind - 1] < rs[i].second)
        rs2.push_back(make_pair(rs[i].first, second[ind] - 1));
      rs2.push_back(rs[i]);
    }
    if (second[second.size() - 2] < rs.back().second)
      rs2.push_back(make_pair(second[second.size() - 2] + 1, n));
    rs.clear();
    sort(rs2.begin(), rs2.end());
    for (long long k = 1; k < rs2.size(); k++)
      if (rs2[k - 1].second >= rs2[k].first) {
        rs2[k].first = rs2[k - 1].first;
        rs2[k - 1].second = -1;
      }
    for (long long k = 0; k < rs2.size(); k++)
      if (rs2[k].first <= rs2[k].second) rs.push_back(rs2[k]);
    if (rs.empty() || (first == n && rs.size() && rs.back().second != n)) {
      cout << -1 << endl;
      return;
    }
    mn = max(mn, rs[0].first);
  }
  cout << 2 * n - 2 << endl;
}
signed main() {
  for (long long i = 0; i < 32; i++) p2[i] = (1 << i);
  cout << fixed << setprecision(12);
  long long t;
  t = 1;
  for (long long i = 1; i <= t; i++) {
    solve();
  }
}
