#include <bits/stdc++.h>
using namespace std;
struct str {
  int st;
  int en;
  bool operator<(const str &b) const {
    return st == b.st ? en < b.en : st < b.st;
  }
};
str ar[100005];
map<int, vector<int> > mss, me, ms;
vector<int> is;
set<int> s;
map<int, int> m;
int demo[100005];
int nv[100005];
int sst[100005];
int main() {
  int a, b, c, d, e, x, y, z, n;
  scanf("%d %d", &n, &z);
  for (a = 0; a < z; a++) {
    scanf("%d %d", &b, &c);
    s.insert(b);
    mss[b].push_back(c);
  }
  set<int>::iterator it;
  it = s.begin();
  b = *it;
  if (b != 1) {
    s.insert(1);
  }
  it = s.end();
  it--;
  b = *it;
  if (b != n) {
    s.insert(n);
  }
  for (it = s.begin(); it != s.end(); it++) {
    b = *it;
    mss[b].push_back(0);
    mss[b].push_back(n + 1);
    sort(mss[b].begin(), mss[b].end());
    c = mss[b].size();
    for (a = 1; a < c; a++) {
      x = mss[b][a - 1] + 1;
      y = mss[b][a] - 1;
      if (x <= y) {
        ms[b].push_back(x);
        me[b].push_back(y);
      }
    }
  }
  m.clear();
  c = 1;
  demo[0] = me[1][0];
  m[me[1][0]] = ms[1][0];
  it = s.begin();
  it++;
  z = 1;
  for (; it != s.end(); it++) {
    b = *it;
    if (z + 1 < b) {
      z = b;
      x = demo[0];
      y = m[x];
      demo[0] = n;
      m.clear();
      m[n] = y;
      c = 1;
    }
    d = 0;
    for (a = 0; a < ms[b].size(); a++) {
      e = lower_bound(demo, demo + c, ms[b][a]) - demo;
      if (e == c) continue;
      e = m[demo[e]];
      if (e <= me[b][a]) {
        nv[d] = a;
        sst[d] = max(e, ms[b][a]);
        d++;
      }
    }
    if (!d) {
      c = 0;
      break;
    }
    m.clear();
    for (a = 0; a < d; a++) {
      demo[a] = me[b][nv[a]];
      m[demo[a]] = sst[a];
    }
    c = d;
    z = b;
  }
  if (!c) {
    cout << -1 << endl;
    return 0;
  }
  c--;
  if (demo[c] != n) {
    cout << -1 << endl;
    return 0;
  }
  cout << 2 * (n - 1) << endl;
  return 0;
}
