#include <bits/stdc++.h>
using namespace std;
long long N;
vector<pair<int, int> > requiredOverlap(vector<pair<int, int> > &upper,
                                        vector<pair<int, int> > &lower) {
  int l1 = upper.size(), l2 = lower.size();
  int up = 0, low = 0;
  vector<pair<int, int> > ans;
  while (up < l1 && low < l2) {
    while (low < l2 && lower[low].first <= upper[up].second) {
      if (lower[low].second >= upper[up].first) {
        ans.push_back(pair<int, int>(max(upper[up].first, lower[low].first),
                                     lower[low].second));
      }
      low++;
    }
    up++;
  }
  return ans;
}
vector<pair<int, int> > makeIntervalForRow(vector<int> &points) {
  vector<pair<int, int> > ans;
  points.push_back(N);
  int start = 0, l = points.size();
  for (int i = 0; i < l; i++) {
    if (start < points[i]) {
      ans.push_back(pair<int, int>(start, points[i] - 1));
      start = points[i] + 1;
    } else {
      start = points[i] + 1;
    }
  }
  return ans;
}
bool operator<(pair<int, int> &a, pair<int, int> &b) {
  if (a.first < b.first)
    return true;
  else if (a.first == b.first)
    return a.second < b.second;
  else
    return false;
}
void print(vector<pair<int, int> > &temp) {
  int l = temp.size();
  for (int i = 0; i < l; i++) {
    cout << "(" << temp[i].first << " " << temp[i].second << ")";
  }
  cout << " rowend" << endl;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  int m;
  cin >> N >> m;
  vector<pair<int, int> > points(m);
  int l = m, a, b;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    points[i].first = a - 1;
    points[i].second = b - 1;
  }
  sort(points.begin(), points.end());
  vector<vector<pair<int, int> > > arr;
  int row = points[0].first, i = 0;
  vector<int> rowOrder;
  while (i < l) {
    row = points[i].first;
    rowOrder.push_back(row);
    vector<int> temp;
    while (i < l && points[i].first == row) {
      temp.push_back(points[i].second);
      i++;
    }
    arr.push_back(makeIntervalForRow(temp));
  }
  if (rowOrder[0] == 0) {
    pair<int, int> t1 = arr[0][0];
    vector<pair<int, int> > t2;
    t2.push_back(t1);
    arr[0] = t2;
  }
  vector<pair<int, int> > final = arr[0];
  bool valid = true;
  int len = arr.size(), currentRow = rowOrder[0];
  for (int i = 1; i < len; i++) {
    if (final.size() == 0) {
      valid = false;
      break;
    } else if ((currentRow + 1) != rowOrder[i]) {
      currentRow = rowOrder[i] - 1;
      pair<int, int> temp1(final[0].first, N - 1);
      vector<pair<int, int> > temp2;
      temp2.push_back(temp1);
      final = temp2;
      i--;
    } else {
      currentRow++;
      final = requiredOverlap(final, arr[i]);
    }
  }
  if (valid) {
    if (final.size() != 0) {
      if (currentRow < N - 1) {
        cout << 2 * (N - 1) << endl;
      } else {
        if (final[final.size() - 1].second == N - 1) {
          cout << 2 * (N - 1) << endl;
        } else {
          cout << -1 << endl;
        }
      }
    } else {
      cout << -1 << endl;
    }
  } else {
    cout << -1 << endl;
  }
}
