#include <bits/stdc++.h>
using namespace std;
int n, k, i, j;
struct dat {
  int l, r;
};
vector<dat> last, now;
pair<int, int> a[100005];
int main() {
  scanf("%d%d", &n, &k);
  for (i = 0; i < k; i++) scanf("%d%d", &a[i].first, &a[i].second);
  sort(a, a + k);
  if (a[0].first == 1)
    now.push_back({1, 1});
  else
    now.push_back({1, n});
  int p, lt;
  for (i = 0; i < k; i++) {
    if (i == 0 || a[i].first != a[i - 1].first) {
      if (i == 0 || a[i].first == a[i - 1].first + 1) {
        last.clear();
        for (j = 0; j < now.size(); j++) last.push_back(now[j]);
        now.clear();
      } else {
        last.clear();
        if (now.size()) last.push_back({now[0].l, n});
        now.clear();
      }
      p = 0;
      lt = 1;
    }
    while (p < last.size() && last[p].r < lt) p++;
    if (p < last.size() && last[p].r >= lt &&
        a[i].second - 1 >= max(lt, last[p].l)) {
      now.push_back({max(lt, last[p].l), a[i].second - 1});
    }
    lt = a[i].second + 1;
    if (i == k - 1 || a[i].first != a[i + 1].first) {
      while (p < last.size() && last[p].r < lt) p++;
      if (p < last.size() && last[p].r >= lt && n >= max(lt, last[p].l)) {
        now.push_back({max(lt, last[p].l), n});
      }
    }
  }
  if (a[k - 1].first != n) {
    last.clear();
    if (now.size()) last.push_back({now[0].l, n});
    now.clear();
  } else {
    last.clear();
    for (j = 0; j < now.size(); j++) last.push_back(now[j]);
    now.clear();
  }
  if (last.size() && last.back().r == n)
    printf("%d\n", 2LL * n - 2);
  else
    printf("-1\n");
}
