#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> v;
vector<vector<pair<int, int>>> points;
vector<vector<pair<int, int>>> interv;
int l, n, m;
void reduce();
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  v.resize(m);
  for (int i(0); i < m; i++) cin >> v[i].first >> v[i].second;
  reduce();
  interv.resize(points.size());
  sort(points[0].begin(), points[0].end());
  if (points[0].empty())
    interv[0].push_back({1, n});
  else
    interv[0].push_back({1, points[0][0].second - 1});
  for (int i(1); i < points.size(); i++) {
    v.clear();
    sort(points[i].begin(), points[i].end());
    int last(1);
    for (auto j : points[i]) {
      if (j.second - 1 >= last) interv[i].push_back({last, j.second - 1});
      last = j.second + 1;
    }
    if (last <= n) interv[i].push_back({last, n});
    for (int a(0), b(0); a < interv[i - 1].size() && b < interv[i].size();) {
      pair<int, int> first(interv[i - 1][a]), second(interv[i][b]);
      if (first.first <= second.first && first.second >= second.first)
        v.push_back(second);
      else if (first.first > second.first && first.first <= second.second)
        v.push_back({first.first, second.second});
      if (first.second < second.second)
        a++;
      else
        b++;
    }
    if (v.empty()) {
      cout << -1;
      return 0;
    }
    interv[i].clear();
    int lastx(v[0].first), lasty(v[0].second);
    for (int j(1); j < v.size(); j++) {
      if (lasty + 1 == v[j].first)
        lasty = v[j].second;
      else {
        interv[i].push_back({lastx, lasty});
        lastx = v[j].first, lasty = v[j].second;
      }
    }
    interv[i].push_back({lastx, lasty});
  }
  if (interv.back().back().second != n)
    cout << -1;
  else
    cout << 2 * n - 2;
  return 0;
}
void reduce() {
  points.emplace_back();
  sort(v.begin(), v.end());
  if (v[0].first != 1) points.emplace_back();
  for (int i(0); i < v.size(); i++) {
    if (i && v[i - 1].first < v[i].first) points.emplace_back();
    if (i && v[i - 1].first + 1 < v[i].first) points.emplace_back();
    points.back().push_back(v[i]);
  }
  if (points.back().back().first != n) points.emplace_back();
}
