#include <bits/stdc++.h>
using namespace std;
int i, j, k;
int dx[] = {1, 1, 1, 0, -1, -1, -1, 0};
int dy[] = {1, 0, -1, -1, -1, 0, 1, 1};
vector<pair<int, int> > vs;
vector<pair<int, int> > vs2;
vector<bool> vis;
bool flag;
int n, m;
bool check(int x, int y) {
  if (x > 0 && y > 0 && x <= n && y <= n) return true;
  return false;
}
void dfs(int x, int y) {
  if (x == 1 || y == n) flag = true;
  int ind =
      (int)(lower_bound(vs.begin(), vs.end(), make_pair(x, y)) - vs.begin());
  if (!flag && !vis[ind]) {
    vis[ind] = true;
    int ii;
    for (ii = 0; ii < 8; ii++) {
      int x1 = x + dx[ii];
      int y1 = y + dy[ii];
      if (check(x1, y1) &&
          binary_search(vs.begin(), vs.end(), make_pair(x1, y1))) {
        dfs(x1, y1);
      }
    }
    vector<pair<int, int> >::iterator l =
        lower_bound(vs.begin(), vs.end(), make_pair(x - 1, 1));
    if ((*l).first == x - 1 && (*l).second < y) {
      dfs((*l).first, (*l).second);
      l++;
    }
    vector<pair<int, int> >::iterator u =
        lower_bound(vs2.begin(), vs2.end(), make_pair(y + 1, x + 1));
    if ((*u).first == y + 1) {
      dfs((*u).second, (*u).first);
      u++;
    }
  }
}
int main() {
  int T = 1;
  ios_base::sync_with_stdio(0);
  for (k = 0; k < T; k++) {
    cin >> n;
    cin >> m;
    int x, y;
    flag = false;
    vector<pair<int, int> > sv;
    for (i = 0; i < m; i++) {
      cin >> x >> y;
      vs.push_back(make_pair(x, y));
      vs2.push_back(make_pair(y, x));
      vis.push_back(false);
      if (y == 1 || x == n) sv.push_back(make_pair(x, y));
    }
    sort((vs).begin(), (vs).end());
    sort((vs2).begin(), (vs2).end());
    for (i = 0; i < sv.size(); i++) {
      int ind = (int)(lower_bound(vs.begin(), vs.end(), sv[i]) - vs.begin());
      if (!vis[ind]) dfs(sv[i].first, sv[i].second);
      if (flag) {
        cout << -1 << endl;
        return 0;
      }
    }
    cout << 2 * (n - 1) << endl;
  }
  return 0;
}
