#include <bits/stdc++.h>
using namespace std;
int n, m, x, y;
int nowx, cur = 1, ncur;
int st, ed, id;
pair<int, int> p[100005];
vector<pair<int, int> > v, nv;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    p[i] = make_pair(x, y);
  }
  sort(p + 1, p + m + 1);
  v.push_back(make_pair(1, 1));
  while (cur <= m) {
    if (v.size() && p[cur].first != nowx + 1) {
      st = v[0].first;
      v.clear();
      v.push_back(make_pair(st, n));
    }
    for (ncur = cur; p[ncur].first == p[cur].first; ncur++)
      ;
    st = 1;
    id = 0;
    nv.clear();
    for (int i = cur; i <= ncur; i++) {
      ed = (i < ncur) ? (p[i].second - 1) : n;
      for (; id < v.size() && v[id].second < st; id++)
        ;
      if (id < v.size() && max(v[id].first, st) <= ed)
        nv.push_back(make_pair(max(v[id].first, st), ed));
      st = ed + 2;
    }
    v = nv;
    nowx = p[cur].first;
    cur = ncur;
  }
  printf("%d\n", (v.size() && (nowx < n || v[v.size() - 1].second == n))
                     ? n * 2 - 2
                     : -1);
}
