#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
pair<int, int> pt[N], q[2][N];
vector<int> E;
int main() {
  int n, m, i, j;
  scanf("%d%d", &n, &m);
  for (i = 0; i < m; i++) {
    scanf("%d%d", &pt[i].first, &pt[i].second);
  }
  sort(pt, pt + m);
  int w[2], pre = 0, now = 1;
  w[pre] = 1;
  q[pre][0].first = q[pre][0].second = 1;
  int pw = 0, ri;
  for (i = 0; i < m; pw = pt[i].first, i = ri) {
    E.clear();
    for (ri = i + 1; ri < m && pt[ri].first == pt[i].first; ri++)
      ;
    for (j = i; j < ri; j++) E.push_back(pt[j].second);
    E.push_back(n + 1);
    if (pw != pt[i].first - 1) {
      q[pre][0].second = n;
      w[pre] = 1;
    }
    w[now] = 0;
    int k = 0, lst = 0;
    for (j = 0; j < w[pre]; j++) {
      if (q[pre][j].first < E[k] && lst != E[k]) {
        q[now][w[now]++] = make_pair(q[pre][j].first, E[k] - 1);
        lst = E[k];
      }
      while (q[pre][j].second > E[k]) {
        if (q[pre][j].first < E[k] + 1) q[pre][j].first = E[k] + 1;
        k++;
        if (q[pre][j].first < E[k] && lst != E[k]) {
          q[now][w[now]++] = make_pair(q[pre][j].first, E[k] - 1);
          lst = E[k];
        }
      }
    }
    if (!w[now]) {
      puts("-1");
      return 0;
    }
    pre = 1 - pre;
    now = 1 - now;
  }
  if (pw < n || q[pre][w[pre] - 1].second == n)
    printf("%d\n", n + n - 2);
  else
    puts("-1");
  return 0;
}
