#include <bits/stdc++.h>
using namespace std;
static const double EPS = 1e-9;
int ROUND(double x) { return (int)(x + 0.5); }
bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; }
bool ISEQUAL(double x, double y) {
  return fabs(x - y) <= EPS * max(1.0, max(fabs(x), fabs(y)));
}
double SQSUM(double x, double y) { return x * x + y * y; }
template <class T>
bool INRANGE(T x, T a, T b) {
  return a <= x && x <= b;
}
template <class T>
void amin(T& a, T v) {
  if (a > v) a = v;
}
template <class T>
void amax(T& a, T v) {
  if (a < v) a = v;
}
struct RANGES {
  inline void init() { num = 0; }
  inline void push(int s, int e) {
    st[num] = s;
    ed[num] = e;
    num++;
  }
  int st[100100];
  int ed[100100];
  int num;
};
struct RG {
  RG(int s, int e) : st(s), ed(e) {}
  int st;
  int ed;
};
vector<RG> r[2];
int main(void) {
  int n, m;
  scanf("%d %d ", &n, &m);
  map<int, vector<int> > mp;
  set<int> st;
  for (int i = 0; i < m; i++) {
    int y, x;
    scanf("%d %d ", &y, &x);
    mp[y].push_back(x);
    st.insert(max(1, y - 1));
    st.insert(y);
    st.insert(min(n, y + 1));
  }
  st.insert(1);
  st.insert(n);
  r[0].clear();
  r[1].clear();
  int now = 0;
  r[now].push_back(RG(1, 1));
  bool ok = false;
  for (auto at = st.begin(); at != st.end(); ++at) {
    const int y = *at;
    sort(mp[y].begin(), mp[y].end());
  }
  for (auto at = st.begin(); at != st.end(); ++at) {
    const int y = *at;
    {
      for (int id = 0; id < ((int)((r[now]).size())); id++) {
      }
      const int next = 1 - now;
      r[next].clear();
      auto it = mp.find(y);
      if (it == mp.end()) {
        r[next].push_back(RG(r[now][0].st, n));
      } else {
        vector<int>& walls = it->second;
        for (int id = 0; id < ((int)((r[now]).size())); id++) {
          bool tsunagi = false;
          if (((int)((r[next]).size())) >= 1) {
            int& last = r[next][((int)((r[next]).size())) - 1].ed;
            if (last + 1 >= r[now][id].st) {
              amax(last, r[now][id].ed);
              tsunagi = true;
            }
          }
          if (!tsunagi) {
            vector<int>::iterator vii =
                lower_bound(walls.begin(), walls.end(), r[now][id].ed);
            if (vii == walls.end()) {
              r[next].push_back(RG(r[now][id].st, n));
            } else {
              r[next].push_back(RG(r[now][id].st, -1 + (*vii)));
            }
          }
        }
      }
      now = next;
    }
    if (y == n) {
      for (int id = 0; id < ((int)((r[now]).size())); id++) {
        if (r[now][id].ed == n) {
          printf("%d\n", 2 * n - 2);
          return 0;
        }
      }
      break;
    }
    {
      const int next = 1 - now;
      r[next].clear();
      auto it = mp.find(y + 1);
      if (it == mp.end()) {
        r[next] = r[now];
      } else {
        vector<int>& walls = it->second;
        for (int id = 0; id < ((int)((r[now]).size())); id++) {
          int cur = r[now][id].st;
          while (cur <= r[now][id].ed) {
            vector<int>::iterator vii =
                lower_bound(walls.begin(), walls.end(), cur);
            if (vii == walls.end()) {
              r[next].push_back(RG(cur, r[now][id].ed));
              break;
            } else if (cur < *vii) {
              r[next].push_back(RG(cur, -1 + *vii));
              cur = 1 + *vii;
            } else if (cur == *vii) {
              cur++;
            }
          }
        }
      }
      if (((int)((r[next]).size())) == 0) {
        break;
      }
      now = next;
    }
  }
  printf("-1\n");
  return 0;
}
