#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, y;
} a[100005];
bool cmp(node a, node b) { return a.x == b.x ? a.y < b.y : a.x < b.x; }
vector<pair<int, int> > q[200005];
vector<int> qa[2], qb[2];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int flag = 0, flag2 = 0;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &a[i].x, &a[i].y);
    if (a[i].x == n) flag = 1;
    if (a[i].x == 1) flag2 = 1;
  }
  sort(a + 1, a + m + 1, cmp);
  int d = 0;
  for (int i = 1; i <= m; i++) {
    if (a[i].x == a[i + 1].x)
      a[i].x = d;
    else {
      if (a[i].x + 1 < a[i + 1].x) {
        a[i].x = d;
        d += 2;
      } else
        a[i].x = d++;
    }
  }
  int top = 0;
  a[m + 1].x = -1;
  for (int i = 1; i <= m; i++) {
    int ok = 0;
    if (1 <= a[i].y - 1) {
      q[top].push_back(make_pair(1, a[i].y - 1));
      ok = 1;
    }
    while (a[i].x == a[i + 1].x) {
      if (a[i + 1].y - 1 >= a[i].y + 1) {
        q[top].push_back(make_pair(a[i].y + 1, a[i + 1].y - 1));
        ok = 1;
      }
      i++;
    }
    if (a[i].y + 1 <= n) {
      q[top].push_back(make_pair(a[i].y + 1, n));
      ok = 1;
    }
    top++;
    if (a[i].x + 1 < a[i + 1].x || i == m && flag == 0)
      q[top++].push_back(make_pair(1, n));
    if (ok == 0) {
      printf("-1\n");
      return 0;
    }
  }
  for (int i = 0; i < top; i++) {
    int L = q[i].size();
    qa[1].clear();
    qb[1].clear();
    if (i == 0 && flag2 == 1) {
      qa[1].push_back(q[0][0].first);
      qb[1].push_back(q[0][0].second);
    }
    for (int j = 0; j < L; j++) {
      pair<int, int> temp = q[i][j];
      int a = temp.first;
      int b = temp.second;
      if (i == 0 && flag2 == 0) {
        qa[1].push_back(a);
        qb[1].push_back(b);
      } else if (i != 0) {
        int sz = qa[0].size();
        int pos = lower_bound(qb[0].begin(), qb[0].end(), a) - qb[0].begin();
        if (pos >= 0 && pos < sz && qa[0][pos] <= b) {
          int a1 = max(qa[0][pos], a);
          qa[1].push_back(a1);
          qb[1].push_back(b);
        }
      }
    }
    if (qa[1].empty()) {
      printf("-1");
      return 0;
    }
    int s = qa[1].size();
    qa[0].clear();
    qb[0].clear();
    for (int j = 0; j < s; j++) {
      qa[0].push_back(qa[1][j]);
      qb[0].push_back(qb[1][j]);
    }
    if (i == top - 1 && qb[0][s - 1] == n) {
      printf("%d\n", 2 * n - 2);
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}
