#include <bits/stdc++.h>
using namespace std;
int N, M;
#pragma warning(disable : 4996)
set<pair<int, int> > sy;
int main() {
  while (scanf("%d %d", &N, &M) != EOF) {
    int x, y;
    sy.clear();
    for (int i = int(0); i < int(M); i++) {
      scanf("%d %d", &x, &y);
      sy.insert(pair<int, int>(y, x));
    }
    int curY = 2;
    auto it = sy.lower_bound(pair<int, int>(2, 0));
    vector<pair<int, int> > s;
    vector<pair<int, int> > &validPositions = s;
    int bigX = N + 1;
    if (sy.begin()->first == 1) bigX = sy.begin()->second;
    validPositions.push_back(pair<int, int>(1, bigX));
    sy.insert(pair<int, int>(N + 1, N + 1));
    while (curY <= N) {
      if (it->first > curY) {
        if (validPositions.size()) {
          int lowest = validPositions[0].first;
          validPositions.clear();
          validPositions.push_back(pair<int, int>(lowest, N + 1));
        }
        curY = it->first;
      } else {
        vector<pair<int, int> > newValids;
        int c = 0, firstEmpty = 1;
        while (it->first == curY) {
          while (c < validPositions.size() &&
                 validPositions[c].second <= firstEmpty)
            c++;
          if (c < validPositions.size()) {
            int sp = max(firstEmpty, validPositions[c].first);
            if (sp < it->second)
              newValids.push_back(pair<int, int>(sp, it->second));
          }
          firstEmpty = it->second + 1;
          it++;
        }
        while (c < validPositions.size() &&
               validPositions[c].second <= firstEmpty)
          c++;
        if (c < validPositions.size()) {
          int sp = max(firstEmpty, validPositions[c].first);
          if (sp <= N) newValids.push_back(pair<int, int>(sp, N + 1));
        }
        validPositions = newValids;
        curY++;
      }
    }
    if (validPositions.size() &&
        validPositions[validPositions.size() - 1].second > N)
      printf("%d\n", N - 1 << 1);
    else
      printf("-1\n");
  }
  return 0;
}
