#include <bits/stdc++.h>
using namespace std;
long n, m, x, y, lp, l[101000], r[101000], l1[101000], r1[101000],
    pos = 1l, pos1 = 1l, prav = 1l;
pair<long, long> a[101000];
bool f;
void prin(long);
int main() {
  cin >> n >> m;
  for (long i = 1l; i <= m; i++) {
    cin >> x >> y;
    a[i] = make_pair(x, y);
  }
  sort(a + 1l, a + m + 1l);
  a[0] = make_pair(0l, 0l);
  if (a[1].first != 1l) {
    l1[1] = 1l;
    r1[1] = n;
    pos++;
    pos1++;
  } else {
    l1[1] = 1l;
    r1[1] = a[1].second - 1l;
    pos++;
    pos1++;
  }
  for (long i = 1l; i <= m; i++) {
    if (pos == 1l) {
      cout << -1;
      cin >> n;
      return 0;
    } else if (a[i].first != 1l) {
      if (a[i].first != a[i - 1l].first) {
        if (a[i - 1].first != 1l) prin(n + 1l);
        for (long j = 1l; j < pos1; j++) {
          l[j] = l1[j];
          r[j] = r1[j];
        }
        pos = pos1;
        if (pos != 1l) {
          pos1 = 1l;
          lp = 1l;
          if (a[i].first - a[i - 1l].first > 1l) {
            l[1] = prav;
            r[1] = n;
            pos = 2l;
          }
        }
      }
      prin(a[i].second);
    }
  }
  if (a[m].first < n && pos1 != 1l) {
    cout << n * 2l - 2l;
    cin >> n;
    return 0;
  }
  prin(n + 1l);
  for (long i = 1l; i < pos1; i++)
    if (r1[i] == n) {
      cout << n * 2l - 2l;
      cin >> n;
      return 0;
    }
  cout << -1;
  cin >> n;
  return 0;
}
void prin(long y1) {
  if (y1 == prav) prav++;
  if (y1 < l[lp]) return;
  if (y1 == l[lp] && lp < pos) {
    l[lp]++;
    if (l[lp] > r[lp]) lp++;
    return;
  }
  if (y1 <= r[lp] && lp < pos) {
    l1[pos1] = l[lp];
    r1[pos1] = y1 - 1l;
    pos1++;
    l[lp] = y1 + 1l;
    if (l[lp] > r[lp]) lp++;
    return;
  }
  if (y1 > r[lp] && lp < pos) {
    l1[pos1] = l[lp];
    r1[pos1] = y1 - 1l;
    pos1++;
    for (; r[lp] < y1 + 1l && lp < pos; lp++)
      ;
    l[lp] = max(l[lp], y1 + 1l);
    return;
  }
}
