#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int n, m; bool bo[200020] = { false }; vector> vec(200020), vec1(200020); vector> ans(200020); int ans1[200020]; void scc(){ vector> mem_co; stack st; int co = 1; for (int i = 0; i < n; i++) { if (!bo[i]) { st.push(i); bo[i] = true; while (!st.empty()) { int now = st.top(); bool stb = false; for (int j = 0; j < vec[now].size(); j++) { if (!bo[vec[now][j]]) { bo[vec[now][j]] = true; stb = true; st.push(vec[now][j]); break; } } if (!stb) { mem_co.emplace_back(make_pair(co, now)); co++; st.pop(); } } } } for (int i = 0; i < n; i++) { bo[i] = false; } sort(mem_co.rbegin(), mem_co.rend()); co = 0; for (int i = 0; i < n; i++) { if (!bo[mem_co[i].second]) { st.push(mem_co[i].second); bo[mem_co[i].second] = true; while (!st.empty()) { int now = st.top(); st.pop(); ans[co].emplace_back(now); ans1[now] = co; for (int j = 0; j < vec1[now].size(); j++) { if (!bo[vec1[now][j]]) { bo[vec1[now][j]] = true; st.push(vec1[now][j]); } } } sort(ans[co].begin(), ans[co].end()); co++; } } } int l[2020], r[2020]; int main() { int n1, m1; cin >> n1 >> m1; n = n1 * 4; for (int i = 0; i < n1; i++) { cin >> l[i] >> r[i]; } for (int i = 0; i < n1; i++) { for (int j = i + 1; j < n1; j++) { if (max(l[i], l[j]) <= min(r[i], r[j])) { vec[i + n1].emplace_back(j); vec1[j].emplace_back(i + n1); vec[j + n1].emplace_back(i); vec1[i].emplace_back(j + n1); } if (max(l[i], m1 - r[j] - 1) <= min(r[i], m1 - l[j] - 1)) { vec[j + n1].emplace_back(i + n1); vec1[i + n1].emplace_back(j + n1); vec[i].emplace_back(j); vec1[j].emplace_back(i); } if (max(l[j], m1 - r[i] - 1) <= min(r[j], m1 - l[i] - 1)) { vec[i + n1].emplace_back(j + n1); vec1[j + n1].emplace_back(i + n1); vec[j].emplace_back(i); vec1[i].emplace_back(j); } if (max(m1 - r[i] - 1, m1 - r[j] - 1) <= min(m1 - l[i] - 1, m1 - l[j] - 1)) { vec[j].emplace_back(i + n1); vec1[i + n1].emplace_back(j); vec[i].emplace_back(j + n1); vec1[j + n1].emplace_back(i); } } } scc(); for (int i = 0; i < m1; i++) { if (ans1[i] == ans1[i + m1]) { cout << "NO" << endl; return 0; } } cout << "YES" << endl; }