#include #include using namespace std; class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x> G1, G2; vector visited; vector cmp, stk; void nya(int v) { visited[v] = true; for(int vv : G1[v]) { if(visited[vv]) { continue; } nya(vv); } stk.push_back(v); } void nyaa(int v, int cnt) { visited[v] = true; for(int vv : G2[v]) { if(visited[vv]) { continue; } nyaa(vv, cnt); } cmp[v] = cnt; } int scc() { visited.assign(N, false); cmp.assign(N, 0); stk.clear(); for(int v : range(N)) { if(visited[v]) { continue; } nya(v); } visited.assign(N, false); int cnt = 0; while(!stk.empty()) { int v = stk.back(); stk.pop_back(); if(visited[v]) { continue; } nyaa(v, cnt++); } return cnt; } void add_edge(int v0, int v1) { G1[v0].push_back(v1); G2[v1].push_back(v0); } void add_edges(int i, int j) { add_edge(i, j); int x = i>=n ? i-n : i+n, y = j>=n ? j-n : j+n; add_edge(y, x); } int rev(int x) { return m-x-1; } int main(void) { scanf("%d%d", &n, &m); vector l(n), r(n); for(int i : range(n)) { scanf("%d%d", &l[i], &r[i]); } N = 2 * n; G1.assign(N, vector()); G2.assign(N, vector()); for(int i : range(n)) { int li0 = l[i], li1 = rev(r[i]), ri0 = r[i], ri1 = rev(l[i]); for(int j : range(i+1, n)) { int lj0 = l[j], lj1 = rev(r[j]), rj0 = r[j], rj1 = rev(l[j]); if(li0 <= rj0 && lj0 <= ri0) { add_edges(i, n+j); } if(li1 <= rj0 && lj0 <= ri1) { add_edges(n+i, n+j); } if(li0 <= rj1 && lj1 <= ri0) { add_edges(i, j ); } if(li1 <= rj1 && lj1 <= ri1) { add_edges(n+i, j ); } } } scc(); for(int i : range(n)) { if(cmp[i] == cmp[n+i]) { puts("NO"); return 0; } } puts("YES"); return 0; }