#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e9 + 7;
const int MAXM = 2e5;
long long N;
int M;
pair<int, int> P[MAXM];
bool isPath() {
  sort(P, P + M);
  if (P[M - 1] == pair<int, int>(N, N)) return false;
  int curRow = 0;
  vector<pair<int, int> > ranges;
  ranges.push_back(pair<int, int>(1, 1));
  for (int i = 0; i < M;) {
    if (P[i].first > curRow + 1) {
      int st = ranges[0].first;
      ranges.clear();
      ranges.push_back(pair<int, int>(st, N));
    }
    vector<pair<int, int> > nranges;
    curRow = P[i].first;
    if (ranges[0].first <= P[i].second - 1)
      nranges.push_back(pair<int, int>(ranges[0].first, P[i].second - 1));
    int j = 0;
    while (i < M && P[i].first == curRow) {
      int st = P[i].second + 1;
      int end;
      if (i + 1 == M || P[i + 1].first != curRow)
        end = N;
      else
        end = P[i + 1].second - 1;
      i++;
      if (st > end) continue;
      while (j < ranges.size() && ranges[j].second < st) {
        j++;
      }
      if (j == ranges.size()) continue;
      if (ranges[j].first <= end)
        nranges.push_back(pair<int, int>(max(st, ranges[j].first), end));
    }
    ranges = nranges;
    if (nranges.empty()) return false;
  }
  if (curRow != N) return !ranges.empty();
  return ranges.back().second == N;
}
long long go() { return isPath() ? (2 * N - 2) : -1; }
int main() {
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> P[i].first >> P[i].second;
  }
  cout << go() << '\n';
}
