#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18 + 7;
const long long mod = 1e9 + 7;
const double eps = 1e-9;
const double PI = 2 * acos(0.0);
const double E = 2.71828;
int n, m;
vector<int> c;
map<int, bool> was[200005];
int x[100005], y[100005];
vector<int> a[200005];
int sz;
vector<pair<int, int> > b[200005];
queue<pair<int, int> > q;
int toall[200005];
bool inter(pair<int, int> a, pair<int, int> b) {
  return max(a.first, b.first) <= min(a.second, b.second);
}
int main(void) {
  scanf("%d %d", &n, &m);
  for (long long(i) = 0; (i) < (long long)(m); (i)++) {
    scanf("%d %d", x + i, y + i);
    --x[i];
    --y[i];
    if (x[i] == n - 1 && y[i] == n - 1) {
      puts("-1");
      exit(0);
    }
    c.push_back(x[i]);
  }
  c.push_back(0);
  c.push_back(n - 1);
  sort((c).begin(), (c).end());
  c.erase(unique((c).begin(), (c).end()), c.end());
  sz = c.size();
  for (int i = 1; i < sz; ++i) {
    if (c[i] != c[i - 1] + 1) {
      toall[i - 1] = true;
    }
  }
  for (long long(i) = 0; (i) < (long long)(m); (i)++) {
    x[i] = lower_bound((c).begin(), (c).end(), x[i]) - c.begin();
    a[x[i]].push_back(y[i]);
  }
  for (long long(i) = 0; (i) < (long long)(sz); (i)++) {
    sort((a[i]).begin(), (a[i]).end());
    a[i].erase(unique((a[i]).begin(), (a[i]).end()), a[i].end());
    if (a[i].empty()) {
      b[i].push_back(make_pair(0, n - 1));
      continue;
    }
    for (long long(j) = 0; (j) < (long long)(a[i].size()); (j)++) {
      if (!j && a[i][0] != 0) {
        b[i].push_back(make_pair(0, a[i][0] - 1));
        continue;
      }
      if (j && a[i][j] - a[i][j - 1] > 1) {
        b[i].push_back(make_pair(a[i][j - 1] + 1, a[i][j] - 1));
      }
    }
    if (a[i].back() != n - 1) {
      b[i].push_back(make_pair(a[i].back() + 1, n - 1));
    }
  }
  if (b[sz - 1].empty()) {
    puts("-1");
    exit(0);
  }
  q.push(make_pair(0, 0));
  was[0][0] = true;
  while (!q.empty()) {
    int x = q.front().first, y = q.front().second;
    q.pop();
    if (x == sz - 1) {
      continue;
    }
    if (toall[x]) {
      pair<int, int> now;
      now = make_pair(b[x][y].first, n - 1);
      for (long long(i) = 0; (i) < (long long)(b[x + 1].size()); (i)++) {
        if (inter(now, b[x + 1][i]) && !was[x + 1].count(i)) {
          was[x + 1][i] = true;
          q.push(make_pair(x + 1, i));
          b[x + 1][i].first = max(b[x + 1][i].first, b[x][y].first);
        }
      }
    } else {
      for (long long(i) = 0; (i) < (long long)(b[x + 1].size()); (i)++) {
        if (inter(b[x][y], b[x + 1][i]) && !was[x + 1].count(i)) {
          was[x + 1][i] = true;
          q.push(make_pair(x + 1, i));
          b[x + 1][i].first = max(b[x + 1][i].first, b[x][y].first);
        }
      }
    }
  }
  if (b[sz - 1].back().second != n - 1) {
    puts("-1");
    exit(0);
  }
  if (was[sz - 1][(int)b[sz - 1].size() - 1]) {
    printf("%d\n", n + n - 2);
  } else {
    puts("-1");
  }
  return 0;
}
