#include #define rep(i, n) for (lli i = 0; i < (n); i++) #define rrep(i, n) for (lli i = (n)-1; i >= 0; i--) using namespace std; using lli = long long int; int main() { int n, m; cin >> n >> m; lli l, r; vector> v; rep(i, n) { cin >> l >> r; if (l >= m / 2) { l = m - 1 - l; r = m - 1 - r; swap(l, r); } v.push_back(make_pair(l, r)); } using p = pair; sort(v.begin(), v.end(), [](p l, p r) -> bool { if (l.first != r.first) return l.first < r.first; return l.second - l.first < r.second - r.first; }); bool used[4005] = {}; rep(i, n) { bool flag = true; for (int j = v[i].first; j <= v[i].second; j++) { if (used[j]) { flag = false; break; } } if (flag) { for (int j = v[i].first; j <= v[i].second; j++) { used[j] = true; } continue; } flag = true; for (int j = m - v[i].second - 1; j <= m - v[i].first - 1; j++) { if (used[j]) { flag = false; break; } } if (flag) { for (int j = m - v[i].second - 1; j <= m - v[i].first - 1; j++) { used[j] = true; } } else { cout << "NO" << endl; return 0; } } cout << "YES" << endl; }