#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i)) #define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i)) #if defined(_MSC_VER) || __cplusplus > 199711L #define aut(r,v) auto r = (v) #else #define aut(r,v) __typeof(v) r = (v) #endif #define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it) #define all(o) (o).begin(), (o).end() #define pb(x) push_back(x) #define mp(x,y) make_pair((x),(y)) #define mset(m,v) memset(m,v,sizeof(m)) #define INF 0x3f3f3f3f #define INFL 0x3f3f3f3f3f3f3f3fLL using namespace std; typedef vector vi; typedef pair pii; typedef vector > vpii; typedef long long ll; template inline void amin(T &x, U y) { if(y < x) x = y; } template inline void amax(T &x, U y) { if(x < y) x = y; } void visit(const vector > &g, int v, vector &scccolor, int &colors, vector &S, vector &inS, vector &low, vector &num, int& time) { low[v] = num[v] = ++time; S.push_back(v); inS[v] = true; each(e, g[v]) { int w = *e; if (num[w] == 0) { visit(g, w, scccolor, colors, S, inS, low, num, time); low[v] = min(low[v], low[w]); } else if (inS[w]) low[v] = min(low[v], num[w]); } if (low[v] == num[v]) { while (1) { int w = S.back(); S.pop_back(); inS[w] = false; scccolor[w] = colors; if (v == w) break; } colors ++; } } int stronglyConnectedComponents(const vector >& g, vector& scccolor) { const int n = g.size(); vector num(n), low(n); vector S; vector inS(n); scccolor.resize(n); int time = 0, colors = 0; rep(u, n) if (num[u] == 0) visit(g, u, scccolor, colors, S, inS, low, num, time); return colors; } bool two_satisfiability(const vector &g) { int n = g.size() / 2; vi scccolor; stronglyConnectedComponents(g, scccolor); rep(i, n) if(scccolor[i] == scccolor[n+i]) return false; return true; } inline bool commonPoint1D(int a, int b, int c, int d) { return c <= b && a <= d; } int main() { int N, M; while(cin >> N >> M) { vi L(N), R(N); rep(i, N) scanf("%d%d", &L[i], &R[i]); vector g(N * 2); rep(i, N) rep(j, i) { int a = L[i], b = R[i], c = L[j], d = R[j]; rep(x, 2) { rep(y, 2) { if(commonPoint1D(a, b, c, d)) { g[x * N + i].push_back((1-y) * N + j); g[y * N + j].push_back((1-x) * N + i); } a = M - 1 - a, b = M - 1 - b, swap(a, b); } c = M - 1 - c, d = M - 1 - d, swap(c, d); } } bool ans = two_satisfiability(g); puts(ans ? "YES" : "NO"); } return 0; }