#include <bits/stdc++.h>
using namespace std;
vector<int> a;
map<int, bool> aa;
map<int, vector<int>> v;
map<int, vector<pair<int, int>>> s;
vector<pair<int, int>> temp;
int main() {
  int i, j, n, m, x, y, z, t, len, pre;
  scanf("%d%d", &n, &m);
  for (i = 0; i < m; i++) {
    scanf("%d%d", &x, &y);
    aa[x] = 1;
    v[x].push_back(y);
    if (x < n) {
      aa[x + 1] = 1;
    }
  }
  aa[1] = 1;
  for (auto p : aa) {
    a.push_back(p.first);
  }
  for (auto p : a) {
    sort(v[p].begin(), v[p].end());
    pre = 1;
    for (auto pp : v[p]) {
      if (pp != pre) {
        s[p].push_back(make_pair(pre, pp - 1));
      }
      pre = pp + 1;
    }
    if (pre <= n) {
      s[p].push_back(make_pair(pre, n));
    }
    if (p == 1) {
      if (s[1].empty() || s[1][0].first != 1) {
        puts("-1");
        return 0;
      }
      while (((int)(s[1]).size()) > 1) {
        s[1].pop_back();
      }
    }
  }
  for (i = 1; i < ((int)(a).size()); i++) {
    pre = a[i - 1];
    temp.clear();
    for (auto p : s[a[i]]) {
      y = -1;
      j = lower_bound(s[pre].begin(), s[pre].end(), make_pair(p.first, 0)) -
          s[pre].begin();
      if (j < ((int)(s[pre]).size()) && s[pre][j].first <= p.second) {
        y = s[pre][j].first;
      }
      if (j > 0 && s[pre][j - 1].second >= p.first) {
        y = p.first;
      }
      if (y != -1) {
        temp.push_back(make_pair(y, p.second));
      }
    }
    if (temp.empty() ||
        (i == ((int)(a).size()) - 1) && temp.back().second != n) {
      puts("-1");
      return 0;
    }
    s[a[i]].clear();
    for (auto p : temp) {
      s[a[i]].push_back(p);
    }
  }
  printf("%d\n", 2 * n - 2);
  ;
  return 0;
}
