#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
struct Range {
  Range(int a = 0) : l(a) {}
  Range(int a, int b) : l(a), r(b) {}
  int l, r;
  bool operator<(const Range &b) const { return l < b.l; }
};
set<Range> ranges;
void upd(int l, int r) {
  if (l >= r) return;
  auto it = ranges.lower_bound(l);
  if (it != ranges.begin()) {
    it--;
    if (it->r > l) {
      auto cur = *it;
      ranges.erase(it);
      ranges.emplace(cur.l, l);
      ranges.emplace(l, cur.r);
    }
  }
  it = ranges.lower_bound(r);
  if (it != ranges.begin()) {
    it--;
    if (it->r > r) {
      auto cur = *it;
      ranges.erase(*it);
      ranges.emplace(cur.l, r);
      ranges.emplace(r, cur.r);
    }
  }
  ranges.erase(ranges.lower_bound(l), ranges.lower_bound(r));
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  map<int, vector<int>> go;
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    go[x].push_back(y);
    if (x == n and y == n) {
      printf("-1\n");
      return 0;
    }
  }
  go[n].push_back(n + 1);
  go[n].pop_back();
  ranges.emplace(1, 2);
  int last = 0;
  for (auto [x, pos] : go) {
    if (ranges.empty()) {
      printf("-1\n");
      return 0;
    }
    sort(pos.begin(), pos.end());
    pos.push_back(n + 1);
    if (last + 1 < x) {
      last = x;
      int y = ranges.begin()->l;
      ranges.clear();
      ranges.emplace(y, n + 1);
      for (int p : pos) upd(p, p + 1);
      if (ranges.empty()) return printf("-1\n"), 0;
      continue;
    }
    last = x;
    for (int p : pos) upd(p, p + 1);
    int prev = -1;
    for (int p : pos) {
      auto it = ranges.lower_bound(p);
      if (it != ranges.begin()) {
        it--;
        if (it->r > prev + 1) {
          auto cur = *it;
          ranges.erase(it);
          ranges.emplace(cur.l, p);
        }
      }
      prev = p;
    }
    if (ranges.empty()) return printf("-1\n"), 0;
  }
  if (prev(ranges.end())->r < n + 1) {
    printf("-1\n");
  } else {
    printf("%d\n", 2 * (n - 1));
  }
}
