#include <bits/stdc++.h>
int n, m;
std::pair<int, int> volcanoes[(100000) + 1];
std::map<int, int> accessible_ranges;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &(volcanoes[i].first), &(volcanoes[i].second));
  }
  sort(volcanoes, volcanoes + m);
  if (1 <= 1) accessible_ranges[1] = 1;
  int lastx = 0;
  for (int i = 0; i < m; ++i) {
    if (volcanoes[i].first - lastx > 1) {
      int begin_pos = accessible_ranges.begin()->second;
      accessible_ranges.clear();
      if (begin_pos <= volcanoes[i].second - 1)
        accessible_ranges[volcanoes[i].second - 1] = begin_pos;
      if (volcanoes[i].second + 1 <= n)
        accessible_ranges[n] = volcanoes[i].second + 1;
    } else {
      std::map<int, int>::iterator next_unprocessed_range;
      if (volcanoes[i].first - lastx == 1) {
        next_unprocessed_range = accessible_ranges.begin();
      } else {
        next_unprocessed_range =
            accessible_ranges.lower_bound(volcanoes[i - 1].second);
      }
      if (next_unprocessed_range != accessible_ranges.end() &&
          next_unprocessed_range->second <= volcanoes[i].second) {
        int begin_pos = next_unprocessed_range->second;
        auto current_range = accessible_ranges.lower_bound(volcanoes[i].second);
        accessible_ranges.erase(next_unprocessed_range, current_range);
        if (begin_pos <= volcanoes[i].second - 1)
          accessible_ranges[volcanoes[i].second - 1] = begin_pos;
      }
      auto current_range = accessible_ranges.lower_bound(volcanoes[i].second);
      if (current_range != accessible_ranges.end() &&
          current_range->second <= volcanoes[i].second) {
        if (volcanoes[i].second == current_range->second) {
          if (current_range->first == current_range->second) {
            accessible_ranges.erase(current_range);
          } else {
            current_range->second++;
          }
        } else {
          if (volcanoes[i].second == current_range->first) {
            accessible_ranges.erase(current_range);
          } else {
            current_range->second = volcanoes[i].second + 1;
          }
        }
      }
      if (accessible_ranges.empty()) break;
    }
    lastx = volcanoes[i].first;
  }
  int ans = -1;
  if (accessible_ranges.size()) {
    auto back = accessible_ranges.end();
    back--;
    if (lastx < n || back->first > volcanoes[m - 1].second) {
      ans = n + n - 2;
    }
  }
  printf("%d", ans);
}
