#include <bits/stdc++.h>
using namespace std;
int is[300010 * 5];
int tree[300010 * 5];
int L, R;
void make(int id, int l, int r) {
  int i;
  if (is[id]) {
    if (l == r) {
      tree[id] = 1;
      is[id] = 0;
      return;
    }
    tree[id] = r - l + 1;
  } else {
    if (l == r) {
      return;
    }
    tree[id] = tree[2 * id] + tree[2 * id + 1];
  }
  return;
}
void spread(int id, int l, int r) {
  if (is[id] == 0) return;
  is[id] = 0;
  is[2 * id] = 1;
  is[2 * id + 1] = 1;
}
void update1(int id, int l, int r) {
  if (r < l) return;
  make(id, l, r);
  if (l > R || r < L) return;
  if (L <= l && r <= R) {
    is[id] = 1;
    make(id, l, r);
    return;
  }
  int mid = (l + r) / 2;
  spread(id, l, r);
  update1(2 * id, l, mid);
  update1(2 * id + 1, mid + 1, r);
  make(id, l, r);
}
void update2(int id, int l, int r) {
  if (r < l) {
    return;
  }
  make(id, l, r);
  if (l > R || r < L) return;
  if (L <= l && r <= R) {
    is[id] = 0;
    tree[id] = 0;
    return;
  }
  int mid = (l + r) / 2;
  spread(id, l, r);
  update2(2 * id, l, mid);
  update2(2 * id + 1, mid + 1, r);
  make(id, l, r);
}
int ret_val;
int ans_got;
void get(int id, int l, int r) {
  if (r < l) return;
  make(id, l, r);
  if (l > R || r < L || ans_got || tree[id] == 0) return;
  int i;
  if (l == r) {
    if (tree[id]) {
      ans_got = 1;
      ret_val = l;
    }
    return;
  }
  int mid = (l + r) / 2;
  spread(id, l, r);
  get(2 * id, l, mid);
  get(2 * id + 1, mid + 1, r);
  make(id, l, r);
}
pair<int, int> pr[100100];
int n1, n2;
int n;
void fill(int l, int r) {
  if (l > r) return;
  L = l;
  R = r;
  ans_got = 0;
  get(1, 1, n2);
  if (ans_got) {
    L = ret_val;
    update1(1, 1, n2);
  }
}
vector<int> vc;
map<int, int> mp;
set<int> s;
int main() {
  int m, i, j, k;
  scanf("%d %d", &n, &m);
  for (i = 0; i < m; i++) {
    scanf("%d %d", &pr[i].first, &pr[i].second);
  }
  s.clear();
  for (i = 0; i < m; i++) {
    s.insert(pr[i].first);
    if ((pr[i].first - 1) >= 1) s.insert(pr[i].first - 1);
    if ((pr[i].first + 1) <= n) s.insert(pr[i].first + 1);
  }
  i = 1;
  for (set<int>::iterator it = s.begin(); it != s.end(); it++) {
    mp[*it] = i++;
  }
  for (i = 0; i < m; i++) {
    pr[i].first = mp[pr[i].first];
  }
  n1 = s.size();
  s.clear();
  for (i = 0; i < m; i++) {
    s.insert(pr[i].second);
    if ((pr[i].second - 1) >= 1) s.insert(pr[i].second - 1);
    if ((pr[i].second + 1) <= n) s.insert(pr[i].second + 1);
  }
  i = 1;
  for (set<int>::iterator it1 = s.begin(); it1 != s.end(); it1++) {
    mp[*it1] = i++;
  }
  for (i = 0; i < m; i++) {
    pr[i].second = mp[pr[i].second];
  }
  n2 = s.size();
  sort(pr, pr + m);
  L = 1;
  R = 1;
  update1(1, 1, n2);
  for (i = 0; i < m;) {
    for (j = i; j < m; j++)
      if (pr[i].first != pr[j].first) break;
    if ((i && (pr[i - 1].first + 1) != pr[i].first) ||
        (i == 0 && pr[0].first != 1)) {
      fill(1, n2);
    }
    vc.clear();
    vc.push_back(0);
    for (k = i; k < j; k++) vc.push_back(pr[k].second);
    vc.push_back(n2 + 1);
    for (k = 0; k < vc.size() - 1; k++) {
      fill(vc[k] + 1, vc[k + 1] - 1);
    }
    for (k = i; k < j; k++) {
      L = pr[k].second;
      R = pr[k].second;
      update2(1, 1, n2);
    }
    i = j;
  }
  if (pr[m - 1].first != n1) {
    fill(1, n2);
  }
  fill(n2, n2);
  if (ans_got == 0)
    printf("-1\n");
  else
    printf("%d\n", 2 * n - 2);
  return 0;
}
