#include <bits/stdc++.h>
using namespace std;
const int maxM = 100010;
vector<pair<int, int> > volcanoes(maxM);
vector<pair<int, int> > cur_range, nxt_range;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  int a, b;
  for (int i = 1; i <= M; i++) {
    cin >> a >> b;
    volcanoes[i] = {a, b};
  }
  sort(volcanoes.begin() + 1, volcanoes.begin() + M + 1);
  int at = 0;
  cur_range.push_back({1, 1});
  bool okay = true;
  for (int i = 1; i <= M;) {
    if (volcanoes[i].first > at + 1) {
      int tmp = cur_range[0].first;
      cur_range.clear();
      cur_range.push_back({tmp, N});
    }
    at = volcanoes[i].first;
    if (cur_range[0].first < volcanoes[i].second)
      nxt_range.push_back({cur_range[0].first, volcanoes[i].second - 1});
    int j = 0;
    int from, to;
    while (i <= M && volcanoes[i].first == at) {
      from = volcanoes[i].second + 1;
      if (i == M || volcanoes[i + 1].first != at)
        to = N;
      else
        to = volcanoes[i + 1].second - 1;
      i++;
      while (j < cur_range.size() && cur_range[j].second < from) j++;
      if (j == cur_range.size()) continue;
      from = max(from, cur_range[j].first);
      if (from <= to) nxt_range.push_back({from, to});
    }
    cur_range = nxt_range;
    nxt_range.clear();
    if (cur_range.empty()) {
      okay = false;
      break;
    }
  }
  if (okay && at == N && cur_range[cur_range.size() - 1].second != N)
    okay = false;
  if (okay)
    cout << (2 * N - 2);
  else
    cout << (-1);
  return 0;
}
