#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int n, m;
pair<int, int> a[200000];
int line[400000];
int linei;
pair<int, int> past[400000];
pair<int, int> now[400000];
int pasti, nowi;
int main() {
  int i, j, k;
  scanf("%d%d", &n, &m);
  for (i = 0; i < m; i++) {
    scanf("%d%d", &a[i].first, &a[i].second);
    a[i].first--, a[i].second--;
    line[i * 2] = a[i].first;
    line[i * 2 + 1] = a[i].first + 1;
  }
  sort(a, a + m);
  sort(line, line + m * 2);
  linei = unique(line, line + m * 2) - line;
  if (line[0] == 0) {
    past[0] = pair<int, int>(0, a[0].second - 1);
    pasti = 1;
  } else {
    past[0] = pair<int, int>(0, n - 1);
    pasti = 1;
  }
  for (i = 0; i < linei; i++) {
    int s, e;
    int x = line[i];
    if (x == 0 || x == n) continue;
    s = lower_bound(a, a + m, pair<int, int>(x, 0)) - a;
    e = upper_bound(a, a + m, pair<int, int>(x, n - 1)) - a - 1;
    nowi = 0;
    if (s > e) {
      now[nowi++] = pair<int, int>(0, n - 1);
    } else {
      int rnow = 0;
      for (j = s; j <= e; j++) {
        now[nowi++] = pair<int, int>(rnow, a[j].second - 1);
        rnow = a[j].second + 1;
      }
      now[nowi++] = pair<int, int>(rnow, n - 1);
    }
    for (j = 0; j < nowi; j++) {
      int po = upper_bound(past, past + pasti,
                           pair<int, int>(now[j].first, now[j].first)) -
               past - 1;
      if (po != -1 && past[po].second >= now[j].first)
        ;
      else {
        int qo = lower_bound(past, past + pasti,
                             pair<int, int>(now[j].first, now[j].first)) -
                 past;
        if (qo >= pasti)
          now[j].first = now[j].second + 1;
        else
          now[j].first = past[qo].first;
      }
    }
    pasti = 0;
    for (j = 0; j < nowi; j++) {
      if (now[j].first > now[j].second) continue;
      past[pasti++] = now[j];
    }
  }
  for (i = 0; i < pasti; i++) {
    if (n - 1 >= past[i].first && n - 1 <= past[i].second) {
      printf("%d", n * 2 - 2);
      return 0;
    }
  }
  printf("-1");
  return 0;
}
