#include <bits/stdc++.h>
using namespace std;
const int MAXM = 1e05 + 10;
struct Valcano {
  int x, y;
  bool operator<(const Valcano& p) const {
    if (x == p.x) return y < p.y;
    return x < p.x;
  }
};
Valcano Valc[MAXM];
int N, M;
vector<pair<int, int> > Sec, newsec, tmp;
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= M; i++) scanf("%d%d", &Valc[i].x, &Valc[i].y);
  sort(Valc + 1, Valc + M + 1);
  int i = 1;
  if (Valc[i].x == 1) {
    Sec.push_back(make_pair(1, Valc[i].y - 1));
    while (Valc[++i].x == 1 && i <= M)
      ;
  } else
    Sec.push_back(make_pair(1, N));
  bool flag = true;
  int last = 1;
  for (; i <= M;) {
    if (Valc[i].x != last + 1) {
      vector<pair<int, int> > newn;
      newn.push_back(make_pair(Sec[0].first, N));
      Sec = newn;
    }
    if (Sec.empty()) {
      flag = false;
      break;
    }
    newsec.clear();
    int type = Valc[i].x, left = i, right = i;
    if (Valc[left].y > 1) newsec.push_back(make_pair(1, Valc[left].y - 1));
    while (Valc[++right].x == type && right <= M)
      if (Valc[right].y > Valc[right - 1].y + 1)
        newsec.push_back(make_pair(Valc[right - 1].y + 1, Valc[right].y - 1));
    if (Valc[right - 1].y < N)
      newsec.push_back(make_pair(Valc[right - 1].y + 1, N));
    tmp.clear();
    int size1 = Sec.size(), size2 = newsec.size();
    int pos = 0;
    for (int j = 0; j < size1; j++) {
      while (pos < size2 && newsec[pos].first <= Sec[j].second) {
        if (newsec[pos].second < Sec[j].first) {
          pos++;
          continue;
        }
        tmp.push_back(make_pair(max(Sec[j].first, newsec[pos].first),
                                newsec[pos].second));
        pos++;
      }
      if (pos >= size2) break;
    }
    Sec = tmp;
    i = right, last = type;
    if (Sec.empty()) {
      flag = false;
      break;
    }
  }
  if (flag && Valc[M].x == N && !Sec.empty())
    if (Sec[Sec.size() - 1].second < N) flag = false;
  if (!flag)
    puts("-1");
  else
    printf("%d\n", 2 * N - 2);
  return 0;
}
