#include using namespace std; #define FOR(i,s,e) for(int (i)=(s);(i)<(int)(e);(i)++) #define REP(i,e) FOR(i,0,e) #define all(o) (o).begin(), (o).end() #define psb(x) push_back(x) typedef long long ll; typedef struct edge_def { int from; int to; int cost; edge_def(int _from, int _to, int _cost) { from = _from; to = _to; cost = _cost; }; } edge; struct SCC { int nv; //頂点数 vector> edges_forward; vector> edges_backward; vector usd; //確定したかチェック用 vector vs; //帰りがけ順の並び vector cmp; //強連結成分のトポロジカル順序 SCC(int nv) { this->nv = nv; edges_forward.resize(nv); edges_backward.resize(nv); usd.resize(nv); cmp.resize(nv); } inline void set_edge(int from, int to, int weight) { edges_forward[from].psb(edge(from,to,weight)); edges_backward[to].psb(edge(to,from,weight)); } void decompose_dfs_forward(int v) { usd[v] = 1; REP(i,(int)edges_forward[v].size()) if (!usd[edges_forward[v][i].to]) decompose_dfs_forward(edges_forward[v][i].to); vs.psb(v); } void decompose_dfs_backward(int v, int k) { usd[v] = 1; cmp[v] = k; REP(i,(int)edges_backward[v].size()) if (!usd[edges_backward[v][i].to]) decompose_dfs_backward(edges_backward[v][i].to, k); } int decompose() { fill(all(usd), 0); vs.clear(); REP(v,nv) if (!usd[v]) decompose_dfs_forward(v); fill(all(usd), 0); int k = 0; REP(i,(int)vs.size()) if (!usd[vs[vs.size()-1-i]]) decompose_dfs_backward(vs[vs.size()-1-i], k++); return k; //decomp scc後のnodeの数 } }; const int N = 2000; const int M = 4000; int n, m; int l[N], r[N]; int main() { scanf("%d%d ", &n, &m); REP(i,n) scanf("%d%d ", l+i, r+i); SCC scc(n*2); REP(i,n) REP(j,i) { int a = l[i], b = r[i], c = l[j], d = r[j]; REP(k,4) { if (k==2) {a = m - 1 - a; b = m - 1 - b; swap(a,b);} if (k>0) {c = m - 1 - c; d = m - 1 - d; swap(c,d);} int x = k/2, y = k&1; if (max(a,c) <= min(b,d)) { scc.set_edge((1-x)*n+i,y*n+j,0); scc.set_edge((1-y)*n+j,x*n+i,0); } } } scc.decompose(); int res = 1; REP(i,n) if (scc.cmp[i]==scc.cmp[n+i]) { res = 0; break; } printf("%s\n", res ? "YES" : "NO"); return 0; }