#include <bits/stdc++.h>
using namespace std;
const int M = 100005;
vector<pair<int, int> > ds;
vector<int> col[M];
int row[M];
vector<pair<int, int> > seg[2];
bool intersect(int tr, int ph, int le, int ri) {
  if (tr > ri || ph < le) return false;
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  ds.resize(m);
  for (int i = 0; i < m; i++) {
    cin >> ds[i].first >> ds[i].second;
    if (ds[i].first == n && ds[i].second == n) {
      cout << -1;
      return 0;
    }
  }
  sort(ds.begin(), ds.end());
  int cnt = -1, tr = 0;
  for (int i = 0; i < m; i++) {
    if (ds[i].first != tr) {
      if (tr > 0) col[cnt].push_back(n + 1);
      cnt++;
      row[cnt] = ds[i].first;
      tr = ds[i].first;
      col[cnt].push_back(0);
    }
    col[cnt].push_back(ds[i].second);
  }
  col[cnt].push_back(n + 1);
  int flag = 0;
  if (row[0] > 1) {
    for (int i = 1; i < col[0].size(); i++)
      if (col[0][i] - col[0][i - 1] > 1) {
        seg[flag].push_back({col[0][i - 1] + 1, col[0][i] - 1});
      }
  } else {
    if (col[0][1] - col[0][0] > 1) {
      seg[flag].push_back({col[0][0] + 1, col[0][1] - 1});
    }
  }
  if ((cnt > 0 && row[1] > row[0] + 1) || (cnt == 0 && row[0] < n)) {
    int old = flag;
    flag ^= 1;
    seg[flag].clear();
    if (seg[old].empty() == false) seg[flag].push_back({seg[old][0].first, n});
  }
  for (int i = 1; i <= cnt; i++) {
    if (seg[flag].empty()) {
      cout << -1;
      return 0;
    }
    int old = flag;
    flag ^= 1;
    seg[flag].clear();
    int k = 0;
    for (int j = 1; j < col[i].size(); j++) {
      if (col[i][j] - col[i][j - 1] > 1) {
        int tr = col[i][j - 1] + 1;
        int ph = col[i][j] - 1;
        while (k < seg[old].size() && seg[old][k].second < tr) k++;
        if (k < seg[old].size() &&
            intersect(tr, ph, seg[old][k].first, seg[old][k].second)) {
          if (tr < seg[old][k].first) tr = seg[old][k].first;
        } else
          continue;
        seg[flag].push_back({tr, ph});
      }
    }
    if ((i < cnt && row[i + 1] > row[i] + 1) || (i == cnt && row[i] < n)) {
      int old = flag;
      flag ^= 1;
      seg[flag].clear();
      if (seg[old].empty() == false)
        seg[flag].push_back({seg[old][0].first, n});
    }
  }
  if (seg[flag].empty() || seg[flag][seg[flag].size() - 1].second != n)
    cout << -1;
  else
    cout << n * 2 - 2;
  return 0;
}
