func_code_string: #include <bits/stdc++.h>   using namespace std;   const int inf = 2000000000;   static inline int Rint() {     struct X {       int dig[256];       X() {         for (int i =  0 ; i <=  9 ; ++i) dig[i] = 1;         dig[ - ] = 1;       }     };     static X fuck;     int s = 1, v = 0, c;     for (; !fuck.dig[c = getchar()];)       ;     if (c ==  - )       s = 0;     else if (fuck.dig[c])       v = c ^ 48;     for (; fuck.dig[c = getchar()]; v = v * 10 + (c ^ 48))       ;     return s ? v : -v;   }   template <typename T>   static inline void cmax(T& a, const T& b) {     if (b > a) a = b;   }   template <typename T>   static inline void cmin(T& a, const T& b) {     if (b < a) a = b;   }   struct Pt {     int x, y;   };   int cmp_x_min(const Pt& a, const Pt& b) {     if (a.x != b.x) return a.x < b.x;     return a.y < b.y;   }   Pt data[100005];   int main() {     int n = Rint(), m = Rint();     for (int i = 0; i < m; ++i) data[i].x = Rint(), data[i].y = Rint();     sort(data, data + m, cmp_x_min);     vector<int> last;     last.push_back(1);     last.push_back(1);     int row = 0;     for (int now = 0; now < m;) {       int j = now + 1;       while (j < m && data[j].x == data[now].x) ++j;       if (last.size() && data[now].x > row + 1) {         vector<int> next;         next.push_back(last.front()), next.push_back(n);         last.swap(next);         row = row + 1;       }       const int size = ((int)(last).size());       vector<int> next;       for (int k = now, pos = 0; k <= j; ++k) {         int r = k == j ? n : data[k].y - 1;         int l = k == now ? 1 : data[k - 1].y + 1;         if (l > r) continue;         while (pos < size && last[pos + 1] < l) pos += 2;         if (pos < size) {           if (last[pos] > r) continue;           if (last[pos] <= l) {             next.push_back(l);             next.push_back(r);           } else if (last[pos] <= r) {             next.push_back(last[pos]);             next.push_back(r);           }         }       }       last.swap(next);       row = data[now].x;       now = j;     }     if (last.size() && data[m - 1].x < n) {       vector<int> next;       next.push_back(last.front()), next.push_back(n);       last.swap(next);       row = row + 1;     }     if (last.size()) {       const int size = ((int)(last).size());       if (last[size - 2] <= n && last[size - 1] >= n) {         printf( %d n , 2 * n - 2);         return 0;       }     }     puts( -1 );     return 0;   }   