#include using namespace std; using ll = long long; // #define int ll using PII = pair; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(x) x.begin(), x.end() template T &chmin(T &a, const T &b) { return a = min(a, b); } template T &chmax(T &a, const T &b) { return a = max(a, b); } template bool IN(T a, T b, T x) { return a<=x&&x T ceil(T a, T b) { return a/b + !!(a%b); } template vector make_v(size_t a) { return vector(a); } template auto make_v(size_t a,Ts... ts) { return vector(ts...))>(a,make_v(ts...)); } template typename enable_if::value==0>::type fill_v(T &t, const V &v) { t=v; } template typename enable_if::value!=0>::type fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); } template ostream &operator <<(ostream& out,const pair& a) { out<<'('< ostream &operator <<(ostream& out,const vector& a){ out<<'['; for(const T &i: a) out< ostream &operator <<(ostream& out, const set& a) { out<<'{'; for(const T &i: a) out< ostream &operator <<(ostream& out, const map& a) { out<<'{'; for(auto &i: a) out<> G; vector> rG; vector vs; vector used; vector cmp; SCC() { V=K=-1; } SCC(int V_): V(V_), G(V_), rG(V_), used(V_), cmp(V_) {} void add_edge(int from,int to) { G[from].push_back(to); rG[to].push_back(from); } void dfs(int v) { used[v]=true; for(int nx: G[v]) if(!used[nx]) dfs(nx); vs.push_back(v); } void rdfs(int v,int k) { used[v]=true; cmp[v]=k; for(int nx: rG[v]) if(!used[nx]) rdfs(nx,k); } int scc() { used.assign(V,0); vs.clear(); for(int v=0;v=0;i--) if(!used[vs[i]]) { rdfs(vs[i],k++); } return K=k; } // O(ElogE) // SCCしたあとのグラフはトポロジカル順になってる vector> getDAG() { vector> res(K); for(int from=0;from ans; twoSAT(ll n) : n(n), graph(n*2), ans(n) {} // not なら false void add(pair a0, pair b0) { ll a = a0.first, ar = (a0.first+n)%(2*n); ll b = b0.first, br = (b0.first+n)%(2*n); if(!a0.second) swap(a, ar); if(!b0.second) swap(b, br); graph.add_edge(ar, b); graph.add_edge(br, a); } bool solve() { graph.scc(); REP(i, n) if(graph.cmp[i] == graph.cmp[n+i]) return false; REP(i, n) ans[i] = graph.cmp[i] > graph.cmp[n+i]; return true; } }; signed main(void) { cin.tie(0); ios::sync_with_stdio(false); ll n, m; cin >> n >> m; vector l(n), r(n); REP(i, n) cin >> l[i] >> r[i]; auto cross = [](ll l1, ll r1, ll l2, ll r2) { const bool comp1 = l1 <= l2 && l2 <= r1; const bool comp2 = l1 <= r2 && r2 <= r1; const bool comp3 = l2 <= l1 && l1 <= r2; const bool comp4 = l2 <= r1 && r1 <= r2; return comp1 || comp2 || comp3 || comp4; }; twoSAT sat(n); REP(i, n-1) { // cout << "i=" << i << endl; if(cross(l[i], r[i], l[i+1], r[i+1])) { // cout << "a" << endl; sat.add({i, false}, {i+1, false}); } if(cross(l[i], r[i], m-r[i+1]+1, m-l[i+1]+1)) { // cout << "b" << endl; sat.add({i, false}, {i+1, true}); } if(cross(m-r[i]+1, m-l[i]+1, l[i+1], r[i+1])) { // cout << "c" << endl; sat.add({i, true}, {i+1, false}); } if(cross(m-r[i]+1, m-l[i]+1, m-r[i+1]+1, m-l[i+1]+1)) { // cout << "d" << endl; sat.add({i, true}, {i+1, true}); } } if(sat.solve()) cout << "YES" << endl; else cout << "NO" << endl; return 0; }