#include <bits/stdc++.h>
using namespace std;
struct node {
  int l, r;
} ar[300000];
bool compare(node a, node b) {
  if (a.r != b.r)
    return a.r < b.r;
  else
    return a.l < b.l;
}
vector<pair<int, int> > vectl, vectn, temp;
int main() {
  int n, i, m, flag = 0;
  scanf("%d%d", &n, &m);
  for (i = 0; i < m; i++) {
    scanf("%d%d", &ar[i].l, &ar[i].r);
  }
  sort(ar, ar + m, compare);
  int col = -1;
  for (int j = 0; j < m; j++) {
    if (ar[j].r != col) {
      ar[i].l = n + 1;
      ar[i].r = ar[j].r;
      col = ar[j].r;
      i++;
    }
  }
  m = i;
  sort(ar, ar + m, compare);
  int row = ar[0].l, lastrow = 1, lastcol = ar[0].r;
  i = 0;
  col = ar[i].r;
  while (ar[i].r == col) {
    if (ar[i].l > lastrow) vectl.push_back(make_pair(lastrow, ar[i].l - 1));
    lastrow = ar[i].l + 1;
    i++;
    if (col == 1) {
      while (ar[i].r == 1) i++;
      break;
    }
  }
  col = ar[i].r;
  while (i < m) {
    if (ar[i].r > lastcol + 1) {
      int st = vectl[0].first;
      lastrow = 1;
      while (ar[i].r == col) {
        if (ar[i].l > lastrow && ar[i].l > st) {
          vectn.push_back(make_pair(lastrow, ar[i].l - 1));
        }
        lastrow = ar[i].l + 1;
        i++;
        if (i >= m) break;
      }
    } else {
      int j = 0;
      lastrow = 1;
      while (ar[i].r == col) {
        while (j < vectl.size() && vectl[j].second < lastrow) j++;
        if (j == vectl.size()) {
          while (i < m && ar[i].r == col) i++;
          break;
        }
        lastrow = max(vectl[j].first, lastrow);
        if (ar[i].l > lastrow) {
          vectn.push_back(make_pair(lastrow, ar[i].l - 1));
        }
        lastrow = ar[i].l + 1;
        i++;
        if (i >= m) break;
      }
    }
    if (i >= m) {
      vectl = vectn;
      lastcol = ar[i - 1].r;
      if (vectl.size() == 0) {
        flag = 1;
      }
      break;
    }
    lastcol = col;
    col = ar[i].r;
    vectl = vectn;
    vectn.clear();
    if (vectl.size() == 0) {
      flag = 1;
      break;
    }
  }
  if (flag == 1)
    printf("-1\n");
  else if (lastcol != n)
    printf("%d\n", n + n - 2);
  else if (vectl[vectl.size() - 1].second == n)
    printf("%d\n", n + n - 2);
  else
    printf("-1\n");
}
