#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> Vs, reach, temp;
struct Node {
  int first, l, r;
  Node(int first = 0, int l = 0, int r = 0) : first(first), l(l), r(r) {}
};
vector<Node> Empty;
void check(bool f) {
  if (!f) {
    puts("-1");
    exit(0);
  }
}
int main() {
  int n, m, x, y;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &x, &y);
    Vs.push_back({x, y});
  }
  sort(Vs.begin(), Vs.end());
  Empty.push_back(Node(0, 1, 1));
  for (int i = 0, j; i < m; i = j) {
    int py = 1, can = 0;
    j = i + 1;
    if (Vs[i].second - 1 >= py) {
      Empty.push_back(Node(Vs[i].first, py, Vs[i].second - 1));
      can = 1;
    }
    py = Vs[i].second + 1;
    while (j < m && Vs[j].first == Vs[i].first) {
      if (Vs[j].second - 1 >= py) {
        Empty.push_back(Node(Vs[i].first, py, Vs[j].second - 1));
        can = 1;
      }
      py = Vs[j].second + 1;
      j++;
    }
    if (py <= n) {
      Empty.push_back(Node(Vs[i].first, py, n));
      can = 1;
    }
    check(can);
  }
  m = Empty.size();
  reach.push_back({1, 1});
  for (int i = 1, j, z; i < m; i = j) {
    j = i + 1;
    while (j < m && Empty[i].first == Empty[j].first) {
      j++;
    }
    if (Empty[i - 1].first + 1 != Empty[i].first) {
      reach[0].second = n;
      reach.resize(1);
    }
    for (int k = i, z = 0; k < j; k++) {
      while (z < reach.size() && reach[z].second < Empty[k].l) z++;
      if (z < reach.size() && reach[z].first <= Empty[k].r) {
        temp.push_back({max(Empty[k].l, reach[z].first), Empty[k].r});
      }
    }
    reach = temp;
    check(!reach.empty());
    temp.clear();
  }
  check(reach.back().second == n || Empty.back().first != n);
  printf("%d\n", n + n - 2);
  return 0;
}
