#include <bits/stdc++.h>
using namespace std;
const int kM = 100010;
int N, M, Xi[kM], Yi[kM];
void read();
void solve();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  read();
  solve();
  return 0;
}
void read() {
  cin >> N >> M;
  for (int i = 0; i < M; ++i) cin >> Xi[i] >> Yi[i];
}
void solve() {
  map<int, vector<int> > m;
  m[1].push_back(N + 1), m[N].push_back(N + 1);
  for (int i = 0; i < M; ++i) {
    m[Xi[i]].push_back(N + 1), m[Xi[i]].push_back(Yi[i]);
    if (Xi[i] > 1) m[Xi[i] - 1].push_back(N + 1);
    if (Xi[i] < N) m[Xi[i] + 1].push_back(N + 1);
  }
  vector<vector<int> > obs;
  for (auto &p : m) {
    vector<int> tmp(p.second);
    sort((tmp).begin(), (tmp).end());
    tmp.erase(unique((tmp).begin(), (tmp).end()), tmp.end());
    obs.push_back(tmp);
  }
  deque<pair<int, int> > que[2];
  int p = 0, q = 1;
  que[q].push_back({1, obs[0].front() - 1});
  for (int k = 0; k < int((obs).size()); ++k) {
    swap(p, q);
    que[q].clear();
    deque<pair<int, int> > &qp = que[p], &qq = que[q];
    for (int i = 0; i < int((qp).size());) {
      int lb = int(lower_bound((obs[k]).begin(), (obs[k]).end(), qp[i].first) -
                   obs[k].begin());
      int rb = int(upper_bound((obs[k]).begin(), (obs[k]).end(), qp[i].second) -
                   obs[k].begin());
      if (lb < rb) {
        int s = qp[i].first;
        for (int j = lb; j <= rb && s <= qp[i].second; ++j) {
          if (s <= obs[k][j] - 1) qq.push_back({s, obs[k][j] - 1});
          s = obs[k][j] + 1;
        }
        ++i;
      } else {
        qq.push_back({qp[i].first, obs[k][lb] - 1});
        while (i < int((qp).size()) && qp[i].second < obs[k][lb]) ++i;
      }
    }
  }
  cout << ((!que[q].empty() && que[q].back().second == N) ? 2 * N - 2 : -1)
       << "\n";
}
