#include using namespace std; typedef long long ll; struct edge { int src, dst; edge(int src, int dst) : src(src), dst(dst) { } }; typedef vector edges; typedef vector Graph; #define VAR(x) ((x) << 1) #define NOT(x) ((x) ^ 1) // !a = NOT(VAR(a)) void visit(int v, const Graph &g, vector &ord, vector &num, int k) { if(num[v] >= 0) return; num[v] = k; for(int i = 0; i < g[v].size(); ++i) visit(g[v][i].dst, g, ord, num, k); ord.push_back(v); } typedef pair clause; // {a or b} pair> two_satisfiability(int m, const vector &cs) { int n = m * 2; // m positive vars and m negative vars Graph g(n), h(n); for(int i = 0; i < cs.size(); ++i) { int u = cs[i].first, v = cs[i].second; g[NOT(u)].push_back(edge(NOT(u), v)); g[NOT(v)].push_back(edge(NOT(v), u)); h[v].push_back(edge(v, NOT(u))); h[u].push_back(edge(u, NOT(v))); } vector num(n, -1), ord, dro; for(int i = 0; i < n; ++i) visit(i, g, ord, num, i); reverse(ord.begin(), ord.end()); fill(num.begin(), num.end(), -1); for(int i = 0; i < n; ++i) visit(ord[i], h, dro, num, i); for(int i = 0; i < n; ++i) { if(num[i] == num[NOT(i)]) return{ false, vector() }; } vector T(m); for(int i = 0; i < m; i++) { if(num[VAR(i)] > num[NOT(VAR(i))]) T[i] = 1; } return{ true, T }; } int L[2000]; int R[2000]; int main() { cin.tie(0); ios::sync_with_stdio(false); int N, M; cin >> N >> M; for(int i = 0; i < N; i++) { cin >> L[i] >> R[i]; } vector cs; for(int i = 0; i < N; i++) { for(int j = i + 1; j < N; j++) { if(!(R[i] < L[j] || R[j] < L[i])) { cs.push_back({ NOT(VAR(i)), VAR(j) }); cs.push_back({ VAR(i), NOT(VAR(j)) }); } int l = M - R[j] + 1, r = M - L[j] + 1; if(!(R[i] < l || r < L[i])) { cs.push_back({ VAR(i), VAR(j) }); cs.push_back({ NOT(VAR(i)), NOT(VAR(j)) }); } } } auto res = two_satisfiability(N, cs); if(res.first) { cout << "YES" << endl; } else { cout << "NO" << endl; } }