#include <bits/stdc++.h>
using namespace std;
int n, m, cnt, i, le, ri;
pair<int, int> a[1000000];
int range[2000210][2], hight[2000010];
bool col1(const pair<int, int> &i, const pair<int, int> &j) {
  if (i.first < j.first) return true;
  if (i.first > j.first) return false;
  return (i.second < j.second);
}
int findRange(int l, int r, int value) {
  int ll = l;
  int rr = r;
  int m;
  while (rr - ll > 1) {
    m = (rr + ll) / 2;
    if (range[m][1] >= value)
      rr = m;
    else
      ll = m;
  }
  if (range[ll][1] >= value) return ll;
  return rr;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int k = 0; k < m; k++) {
    scanf("%d %d", &a[k].first, &a[k].second);
  }
  sort(a, a + m, col1);
  i = 0;
  le = 0;
  ri = 0;
  cnt = 0;
  int index;
  while (i < m) {
    int l = 1;
    int r = -1;
    int h = a[i].first;
    while (i < m && h == a[i].first) {
      l = r + 2;
      r = a[i].second - 1;
      if (r >= l)
        if (cnt > 0 && a[i].first == 1)
          l = r + 1;
        else if ((!(cnt == 0 || (le == ri && ri == 0 && a[i].first > 1))) &&
                 r >= l) {
          index = (hight[ri] + 1 < a[i].first ? findRange(le, ri, 1)
                                              : findRange(le, ri, l));
          l = (((range[index][1] >= l) || (hight[index] + 1 < a[i].first))
                   ? max(l, range[index][0])
                   : 2 * 1000 * 1000 * 1000);
        }
      if (r >= l) {
        cnt++;
        hight[cnt] = a[i].first;
        range[cnt][0] = l;
        range[cnt][1] = r;
      }
      i++;
    }
    l = a[i - 1].second + 1;
    r = n;
    if (r >= l && a[i - 1].first > 1) {
      if (!(le == ri && ri == 0 && a[i - 1].first > 1) && r >= l) {
        index = (hight[ri] + 1 < a[i - 1].first ? findRange(le, ri, 1)
                                                : findRange(le, ri, l));
        l = (((range[index][1] >= l) || (hight[index] + 1 < a[i - 1].first))
                 ? max(l, range[index][0])
                 : 2 * 1000 * 1000 * 1000);
      }
      if (r >= l) {
        cnt++;
        hight[cnt] = a[i - 1].first;
        range[cnt][0] = l;
        range[cnt][1] = r;
      }
    }
    le = ri + 1;
    ri = cnt;
    if (le > ri) {
      printf("-1");
      exit(0);
    }
  }
  if (range[cnt][1] == n || (hight[cnt] < n))
    printf("%d", n * 2 - 2);
  else
    printf("-1");
  return 0;
}
