#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
struct point {
  int x, y, id;
  point() {}
  point(int x, int y, int id) : x(x), y(y), id(id) {}
} a[N];
vector<int> v[N];
int visit[N];
void dfs(int u) {
  visit[u] = 1;
  for (int i = 0; i < v[u].size(); i++)
    if (!visit[v[u][i]]) dfs(v[u][i]);
}
bool cmpx(const point &p, const point &q) {
  if (p.x != q.x) return p.x < q.x;
  return p.y < q.y;
}
bool cmpy(const point &p, const point &q) {
  if (p.y != q.y) return p.y < q.y;
  return p.x < q.x;
}
void build_graph(int n) {
  sort(a + 1, a + n + 1, cmpx);
  for (int i = 1; i <= n; i++) {
    int x = a[i].x, y = a[i].y, id = a[i].id;
    int lt = i + 1, rt = n, mid, tmp = -1;
    while (lt <= rt) {
      mid = (lt + rt) / 2;
      if (a[mid].x > x + 1)
        rt = mid - 1;
      else if (a[mid].x < x + 1)
        lt = mid + 1;
      else if (a[mid].y < y - 1)
        lt = mid + 1;
      else {
        tmp = mid;
        rt = mid - 1;
      }
    }
    if (tmp == -1) continue;
    v[a[tmp].id].push_back(id);
  }
  sort(a + 1, a + n + 1, cmpy);
  for (int i = 1; i <= n; i++) {
    int x = a[i].x, y = a[i].y, id = a[i].id;
    int lt = i + 1, rt = n, mid, tmp = -1;
    while (lt <= rt) {
      mid = (lt + rt) / 2;
      if (a[mid].y > y + 1)
        rt = mid - 1;
      else if (a[mid].y < y + 1)
        lt = mid + 1;
      else if (a[mid].x < x - 1)
        lt = mid + 1;
      else {
        tmp = mid;
        rt = mid - 1;
      }
    }
    if (tmp == -1) continue;
    v[id].push_back(a[tmp].id);
  }
}
int main() {
  int S = 0, T = N - 1;
  int n, m, x, y;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    a[i] = point(x, y, i);
    if (x == n && y == n) {
      cout << -1 << endl;
      return 0;
    }
    if (x == n || y == 1)
      v[S].push_back(i);
    else if (x == 1 || y == n)
      v[i].push_back(T);
  }
  build_graph(m);
  dfs(S);
  if (!visit[T])
    cout << 2 * (n - 1) << endl;
  else
    cout << -1 << endl;
  return 0;
}
