#include <bits/stdc++.h>
using namespace std;
int n, m, _, __;
struct pii : public pair<int, int> {
  int id;
  pii() {}
  pii(int first, int second) {
    this->first = first;
    this->second = second;
  }
  pii(int first, int second, int id) {
    this->first = first;
    this->second = second;
    this->id = id;
  }
};
queue<pii> q;
vector<pii> sx, sy;
bool visited[300000];
const auto cmp = [](const pii& i, const pii& j) {
  return i.second != j.second ? i.second < j.second : i.first > j.first;
};
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &_, &__);
    sx.emplace_back(_, __, i);
    sy.emplace_back(_, __, i);
    if (_ == 1 || __ == n) q.emplace(_, __), i[visited] = 1;
  }
  sort(sx.begin(), sx.end());
  sort(sy.begin(), sy.end(), cmp);
  while (q.size()) {
    _ = q.front().first;
    __ = q.front().second;
    q.pop();
    if (_ == n || __ == 1) return puts("-1"), 0;
    auto it = lower_bound(sx.begin(), sx.end(), pii{_ + 1, __ - 1}),
         jt = lower_bound(sy.begin(), sy.end(), pii{_ + 1, __ - 1}, cmp);
    if (it != sx.end() && it->first == _ + 1 && !visited[it->id]) {
      visited[it->id] = 1;
      q.emplace(it->first, it->second);
    }
    if (jt != sy.end() && jt->second == __ - 1 && !visited[jt->id]) {
      visited[jt->id] = 1;
      q.emplace(jt->first, jt->second);
    }
  }
  printf("%d\n", n * 2 - 2);
}
