#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
int n, m;
map<int, vector<int> > cols;
map<int, vector<pair<int, int> > > ranges;
int main() {
  scanf("%d %d", &n, &m);
  vector<int> all;
  for (int i = int(0); i < int(m); i++) {
    int r, c;
    scanf("%d %d", &r, &c);
    all.push_back(r);
    if (r < n) {
      all.push_back(r + 1);
    }
    cols[r].push_back(c);
  }
  all.push_back(1);
  sort(all.begin(), all.end());
  all.erase(unique(all.begin(), all.end()), all.end());
  for (auto &each : all) {
    auto &cur = cols[each];
    auto &cur_range = ranges[each];
    sort(cur.begin(), cur.end());
    int start = 1;
    for (int i = int(0); i < int(cur.size()); i++) {
      int ending = cur[i];
      if (start != ending) {
        cur_range.emplace_back(start, ending - 1);
      }
      start = ending + 1;
    }
    if (start <= n) {
      cur_range.emplace_back(start, n);
    }
    if (each == 1) {
      if (cur_range.empty() || cur_range[0].first != 1) {
        puts("-1");
        return 0;
      }
      while ((int)cur_range.size() > 1) {
        cur_range.pop_back();
      }
    }
  }
  for (int i = int(1); i < int(all.size()); i++) {
    auto &prev = ranges[all[i - 1]];
    auto &cur = ranges[all[i]];
    vector<pair<int, int> > to_add;
    for (auto &each : cur) {
      auto it = lower_bound(prev.begin(), prev.end(), make_pair(each.first, 0));
      int pl = -1;
      if (it != prev.end()) {
        if (each.second >= it->first) {
          pl = it->first;
        }
      }
      if (it != prev.begin()) {
        it--;
        if (it->second >= each.first) {
          pl = each.first;
        }
      }
      if (pl != -1) {
        to_add.emplace_back(pl, each.second);
      }
    }
    if (to_add.empty() ||
        ((i == (int)all.size() - 1) && to_add.back().second != n)) {
      puts("-1");
      return 0;
    }
    cur.clear();
    for (auto &each : to_add) {
      cur.push_back(each);
    }
  }
  printf("%d\n", 2 * n - 2);
  return 0;
}
