#include #include #include using namespace std; #define RREP(i,s,e) for (i = s; i >= e; i--) #define rrep(i,n) RREP(i,n,0) #define REP(i,s,e) for (i = s; i < e; i++) #define rep(i,n) REP(i,0,n) #define INF 100000000 typedef long long ll; vector e[4000]; vector re[4000]; vector vs; bool used[4000]; int cmp[4000]; int n; void add_edge(int u, int v) { e[u].push_back(v); re[v].push_back(u); } void dfs(int x) { int i; used[x] = true; rep (i,e[x].size()) if (!used[e[x][i]]) dfs(e[x][i]); vs.push_back(x); } void rdfs(int x, int d) { int i; used[x] = true; cmp[x] = d; rep (i,re[x].size()) if (!used[re[x][i]]) rdfs(re[x][i],d); } void scc() { int i, d; rep (i,2*n) if (!used[i]) dfs(i); fill(used,used+2*n,false); d = 0; rrep (i,2*n-1) if (!used[i]) rdfs(i,d++); } int main() { int i, j, m; int l[2000], r[2000]; bool ans; cin >> n >> m; rep (i,n) cin >> l[i] >> r[i]; rep (i,n) rep (j,i) { if (max(l[i],l[j])<=min(r[i],r[j])) { add_edge(i,j+n); add_edge(j,i+n); } if (max(l[i],m-1-r[j])<=min(r[i],m-1-l[j])) { add_edge(i,j); add_edge(j+n,i+n); } if (max(m-1-r[i],l[j])<=min(m-1-l[i],r[j])) { add_edge(i+n,j+n); add_edge(j,i); } if (max(m-1-r[i],m-1-l[j])<=min(m-1-l[i],m-1-l[j])) { add_edge(i+n,j); add_edge(j+n,i); } } scc(); ans = true; rep (i,n) if (cmp[i] == cmp[i+n]) ans = false; if (ans) cout << "YES" << endl; else cout << "NO" << endl; return 0; }