#include <bits/stdc++.h>
using namespace std;
class segTree {
  struct node {
    node *lft, *rgt;
    int lmostOne;
    int ytp;
    int pval;
    node() {
      lft = rgt = NULL;
      ytp = 0;
      lmostOne = 1000000050;
    }
    void push(int cl, int cr) {
      if (!ytp) return;
      ytp = 0;
      int mid = (cl + cr) / 2;
      if (lft == NULL) lft = new node();
      if (rgt == NULL) rgt = new node();
      lft->ytp = 1;
      lft->pval = pval;
      if (pval == 0)
        lft->lmostOne = 1000000050;
      else
        lft->lmostOne = cl;
      rgt->ytp = 1;
      rgt->pval = pval;
      if (pval == 0)
        rgt->lmostOne = 1000000050;
      else
        rgt->lmostOne = mid + 1;
    }
    int upd(int val, int cl) {
      ytp = 1;
      pval = val;
      if (val == 0)
        lmostOne = 1000000050;
      else
        lmostOne = cl;
      return lmostOne;
    }
  };
  node *top;
  int N;

 public:
  segTree(int _N) {
    top = NULL;
    N = _N;
  }
  int update(node *&cur, int cl, int cr, int al, int ar, int val) {
    if (cl > ar || al > cr) return (cur == NULL ? 1000000050 : cur->lmostOne);
    if (cur == NULL) cur = new node();
    cur->push(al, ar);
    if (al >= cl && ar <= cr) return cur->upd(val, al);
    int mid = (al + ar) / 2;
    return cur->lmostOne = min(update(cur->lft, cl, cr, al, mid, val),
                               update(cur->rgt, cl, cr, mid + 1, ar, val));
  }
  int query(node *cur, int cl, int cr, int al, int ar) {
    if (cl > ar || al > cr) return 1000000050;
    if (cur == NULL) return 1000000050;
    cur->push(al, ar);
    if (al >= cl && ar <= cr) return cur->lmostOne;
    int mid = (al + ar) / 2;
    return min(query(cur->lft, cl, cr, al, mid),
               query(cur->rgt, cl, cr, mid + 1, ar));
  }
  int U(int cl, int cr, int val) {
    if (cl > cr) return 1000000050;
    return update(top, cl, cr, 0, N, val);
  }
  int Q(int cl, int cr) {
    if (cl > cr) return 1000000050;
    return query(top, cl, cr, 0, N);
  }
};
segTree *st;
vector<pair<int, int> > walls;
int main() {
  int n, m, w;
  long long int ans = 0;
  ans = 0;
  cin >> n >> w;
  m = n;
  pair<pair<int, int>, pair<int, int> > cwall;
  set<int> s;
  walls.clear();
  while (w--) {
    int x, y;
    cin >> x >> y;
    walls.push_back(make_pair(x, y));
    s.insert(x);
  }
  for (set<int>::iterator it = s.begin(); it != s.end(); it++)
    walls.push_back(make_pair(*it, n + 1));
  st = new segTree(m + 1);
  sort(walls.begin(), walls.end());
  st->U(1, 1, 1);
  int i;
  int prow = 0;
  int lft = n + 1;
  for (i = 0; i < (int)walls.size(); i++) {
    if (walls[i].first - prow > 1) {
      int lmostOne;
      lmostOne = st->Q(1, n);
      if (lmostOne <= n) st->U(lmostOne, n, 1);
    }
    if (walls[i].first != prow) lft = 1;
    if (lft <= walls[i].second - 1) {
      int lmostOne = st->Q(lft, walls[i].second - 1);
      if (lmostOne <= n) {
        st->U(lmostOne, walls[i].second - 1, 1);
        st->U(lft, lmostOne - 1, 0);
      }
    }
    st->U(walls[i].second, walls[i].second, 0);
    lft = walls[i].second + 1;
    prow = walls[i].first;
  }
  if (prow != n) {
    int lmostOne = st->Q(1, n);
    if (lmostOne <= n) st->U(lmostOne, n, 1);
  }
  if (st->Q(n, n) == n)
    cout << 2 * n - 2 << endl;
  else
    cout << -1 << endl;
  return 0;
}
