#include #include #include #include #include #include #include #include #include #include using namespace std; bool comp(const pair& x, const pair& y){ if(x.second != y.second) return x.second < y.second; else return x.first < y.first; } int main(){ int n,m; cin >> n >> m; vector L(n),R(n); for(int i=0; i> L[i] >> R[i]; } vector> v(n); for(int i=0; i= m/2){ swap(L[i], R[i]); L[i] = m-1 - L[i]; R[i] = m-1 - R[i]; } v[i] = {L[i], R[i]}; } sort(v.begin(), v.end(), comp); vector> next; next.push_back({-1,m}); for(int i=0; i> next_; int r__ = m; int l__ = -1; int l = v[i].first; int r = v[i].second; int rl = m-1 - r; int rr = m-1 - l; for(int j=0; j