func_code_string: #include <bits/stdc++.h>   bool local = false;   using namespace std;   template <class T>   string toString(T x) {     ostringstream sout;     sout << x;     return sout.str();   }   template <class T>   void print(T v) {     cout << ((int)(v).size()) <<   n ;     for (auto x : v) cout << x <<    ;     cout <<   n ;   };   template <class T1, class T2>   ostream &operator<<(ostream &o, pair<T1, T2> x) {     return o << x.first <<     << x.second;   }   template <class T1, class T2>   istream &operator>>(istream &o, pair<T1, T2> &x) {     return o >> x.first >> x.second;   }   template <class T1, class T2>   pair<T1, T2> operator+(pair<T1, T2> a, pair<T1, T2> b) {     a.first += b.first;     a.second += b.second;     return a;   }   template <class T1, class T2>   pair<T1, T2> operator-(pair<T1, T2> a, pair<T1, T2> b) {     a.first -= b.first;     a.second -= b.second;     return a;   }   template <class T1, class T2>   void operator+=(pair<T1, T2> &a, pair<T1, T2> b) {     a.first += b.first;     a.second += b.second;   }   template <class T1, class T2>   void operator-=(pair<T1, T2> &a, pair<T1, T2> b) {     a.first -= b.first;     a.second -= b.second;   }   int nint() {     int x;     cin >> x;     return x;   }   double getTime() { return clock() / (double)CLOCKS_PER_SEC; };   mt19937 rnd(0);   int rand(int n) { return rnd() % n; }   int rand(int l, int r) { return rnd() % (r - l + 1) + l; }   const int mod = 1000000000 + 7;   void initIO() {     if (local) {       freopen( input.txt ,  r , stdin);       srand((int)time(0));       rnd.seed((int)time(0));     } else {     }     {       ios::sync_with_stdio(0);       cin.tie(0);       cout.tie(0);     };   }   int m;   int n;   vector<pair<int, int> > v;   vector<int> v1, v2;   const int K = 19;   bool f(pair<int, int> a, pair<int, int> b) {     if (a.first != b.first) return a.first < b.first;     return a.second > b.second;   }   vector<pair<int, int> > update(vector<pair<int, int> > v) {     vector<pair<int, int> > ans;     ans.emplace_back(v[0]);     for (int i = 1; i < ((int)(v).size()); i++) {       pair<int, int> x = ans.back();       pair<int, int> y = v[i];       if (y.second <= x.second) continue;       ans.emplace_back(y);     }     return ans;   }   int get(int x) {     int p = upper_bound(v1.begin(), v1.end(), x) - v1.begin() - 1;     if (p == -1) return -1;     return p;   }   int ne[K + 1][200500];   void calc() {     for (int i = 0; i < (n); i++) ne[0][i] = i;     for (int t = 1; t < K; t++) {       for (int i = 0; i < (n); i++) {         int x = v2[ne[t - 1][i]];         int id = get(x);         x = ne[t - 1][id];         ne[t][i] = x;       }     }   }   int getans(int x, int y) {     int p = get(x);     if (p == -1) return -1;     int ans = 1;     for (int i = K - 1; i > 0; i--) {       while (1) {         int np = ne[i][p];         if (p == np) break;         if (v2[np] < y) {           p = np;           ans += (1 << i) - 1;         } else           break;       }     }     if (v2[p] < y) {       p = ne[1][p];       ans++;     }     if (v[p].second < y) return -1;     return ans;   }   int main() {     initIO();     cin >> n >> m;     for (int i = 0; i < (n); i++) {       int l, r;       cin >> l >> r;       v.emplace_back(l, r);     }     sort(v.begin(), v.end(), f);     v = update(v);     n = ((int)(v).size());     for (int i = 0; i < (n); i++) {       v1.emplace_back(v[i].first);       v2.emplace_back(v[i].second);     };     ;     ;     ;     calc();     for (int i = 0; i < (m); i++) {       int l, r;       cin >> l >> r;       cout << getans(l, r) <<   n ;     }   }   