#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
const int MOD = 1000000007;
struct Point {
  int x, y;
  inline void input() { scanf("%d %d", &x, &y); }
  bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; }
} p[N];
int n, m, x[N];
map<int, int> mymap;
vector<int> y[N];
set<pair<int, int> > myset[2];
set<pair<int, int> >::iterator it;
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    p[i].input();
    if (p[i].x == n && p[i].y == n) {
      puts("-1");
      return 0;
    }
  }
  sort(p, p + m);
  if (m == 0) {
    printf("%d\n", 2 * n - 2);
    return 0;
  }
  int cnt = 0;
  for (int i = 0; i < m; i++) {
    if (mymap.find(p[i].x) == mymap.end()) {
      x[cnt] = p[i].x;
      mymap[p[i].x] = cnt++;
    }
    y[mymap[p[i].x]].push_back(p[i].y);
  }
  for (int i = 0; i < cnt; i++) {
    y[i].push_back(0);
    y[i].push_back(n + 1);
    sort(y[i].begin(), y[i].end());
  }
  if (x[0] == 1) {
    myset[0].insert(make_pair(1, y[0][1] - 1));
  } else {
    int size = y[0].size();
    for (int j = 0; j < size - 1; j++) {
      if (y[0][j] + 1 < y[0][j + 1])
        myset[0].insert(make_pair(y[0][j] + 1, y[0][j + 1] - 1));
    }
  }
  for (int i = 1; i < cnt; i++) {
    int pre = (i + 1) & 1, now = i & 1;
    if (myset[pre].size() == 0) {
      puts("-1");
      return 0;
    }
    myset[now].clear();
    if (x[i] != x[i - 1] + 1) {
      int p = (*myset[pre].begin()).first;
      myset[pre].clear();
      myset[pre].insert(make_pair(p, n));
    }
    int size = y[i].size();
    it = myset[pre].begin();
    for (int j = 0; j < size - 1; j++) {
      while (it != myset[pre].end() && it->second <= y[i][j]) {
        it++;
      }
      if (y[i][j] + 1 < y[i][j + 1] && it != myset[pre].end() &&
          it->second > y[i][j] && it->first < y[i][j + 1]) {
        myset[now].insert(
            make_pair(max(y[i][j] + 1, it->first), y[i][j + 1] - 1));
      }
    }
  }
  int p = (cnt + 1) & 1;
  if (myset[p].size() == 0)
    puts("-1");
  else {
    if (x[cnt - 1] == n) {
      it = myset[p].end();
      it--;
      if (it->second < n) {
        puts("-1");
        return 0;
      }
    }
    printf("%d\n", 2 * n - 2);
  }
  return 0;
}
