#include <bits/stdc++.h>
using namespace std;
struct point {
  int x, y;
  point(int x, int y) : x(x), y(y) {}
};
struct event {
  int y;
  int type;
  event(int y, int type) : y(y), type(type) {}
};
bool operator<(const point& left, const point& right) {
  if (left.x < right.x)
    return true;
  else if (left.x == right.x)
    return left.y < right.y;
  else
    return false;
}
int N, M;
vector<point> points;
void dump(int x, const vector<event>& events) {}
int main(int argc, const char* argv[]) {
  vector<event> events[2];
  int cur = 0;
  int cp = 0;
  int lastx;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    points.push_back(point(x - 1, y - 1));
  }
  if (N == 1) {
    cout << "0" << endl;
    return 0;
  }
  sort(points.begin(), points.end());
  if (points[0].x > 0) {
    events[cur].push_back(event(0, 0));
    events[cur].push_back(event(N, 1));
    lastx = -1;
  } else {
    events[cur].push_back(event(0, 0));
    events[cur].push_back(event(points[0].y, 1));
    lastx = 0;
  }
  dump(0, events[cur]);
  while (cp < points.size() && points[cp].x == 0) cp++;
  while (cp < points.size()) {
    int curx = points[cp].x;
    int newcur = cur ^ 1;
    if (events[cur].empty()) {
      cout << "-1" << endl;
      return 0;
    }
    events[newcur].clear();
    if (points[cp].x != lastx + 1) {
      int miny = events[cur][0].y;
      events[cur].clear();
      events[cur].push_back(event(miny, 0));
      events[cur].push_back(event(N, 1));
    }
    lastx = points[cp].x;
    int curevent = 0;
    int status = 1;
    while (cp < points.size() && points[cp].x == curx &&
           curevent < events[cur].size()) {
      if (status == 1) {
        assert(events[cur][curevent].type == 0);
        if (points[cp].y < events[cur][curevent].y) {
          cp++;
        } else if (points[cp].y == events[cur][curevent].y) {
          events[cur][curevent].y++;
          if (events[cur][curevent + 1].y == events[cur][curevent].y)
            curevent += 2;
          cp++;
        } else {
          events[newcur].push_back(event(events[cur][curevent].y, 0));
          curevent++;
          status = 0;
        }
      } else {
        assert(events[cur][curevent].type == 1);
        if (points[cp].y < events[cur][curevent].y) {
          events[newcur].push_back(event(points[cp].y, 1));
          int nexty = points[cp].y;
          do {
            nexty++;
            cp++;
            if (nexty == events[cur][curevent].y) {
              status = 1;
              curevent++;
              break;
            }
          } while (cp < points.size() && points[cp].x == curx &&
                   points[cp].y == nexty);
          if (status == 0) events[newcur].push_back(event(nexty, 0));
        } else {
          while (curevent < events[cur].size() &&
                 events[cur][curevent].y < points[cp].y)
            curevent++;
          if (curevent < events[cur].size()) {
            if (events[cur][curevent].type == 1) {
              if (events[cur][curevent].y == points[cp].y) {
                events[newcur].push_back(event(points[cp].y, 1));
                status = 1;
                cp++;
                curevent++;
              }
              continue;
            }
            events[newcur].push_back(event(points[cp].y, 1));
            status = 1;
          } else {
            events[newcur].push_back(event(points[cp].y, 1));
            status = 1;
          }
        }
      }
    }
    if (curevent < events[cur].size()) {
      if (status == 0) {
        assert(events[cur][curevent].type == 1);
        events[newcur].push_back(event(N, 1));
      } else {
        assert(events[cur][curevent].type == 0);
        events[newcur].push_back(events[cur][curevent]);
        events[newcur].push_back(event(N, 1));
      }
    }
    while (cp < points.size() && points[cp].x == curx) cp++;
    cur ^= 1;
    dump(curx, events[cur]);
  }
  if (lastx != N - 1) {
    if (events[cur].empty())
      cout << "-1" << endl;
    else
      cout << (2 * N - 2) << endl;
  } else {
    if (events[cur].empty() || events[cur][events[cur].size() - 1].y < N)
      cout << "-1" << endl;
    else
      cout << (2 * N - 2) << endl;
  }
  return 0;
}
