class SCC: def __init__(self, n): self.n = n self.g = [[] for i in range(n)] self.rg = [[] for i in range(n)] def add_edge(self, a, b): self.g[a].append(b) self.rg[b].append(a) def scc(self): def _dfs(v): stack = [v] used[v] = True while stack: v = stack[-1] flag = True for u in self.g[v]: if not used[u]: flag = False used[u] = True stack.append(u) break if flag: stack.pop() vs.append(v) def _rdfs(v, k): stack = [v] used[v] = True cmp[v] = k while stack: v = stack[-1] stack.pop() used[v] = True for u in self.rg[v]: if not used[u]: cmp[u] = k stack.append(u) vs = [] # post order cmp = [-1]*self.n used = [False]*self.n for v in range(self.n): if not used[v]: _dfs(v) k = -1 used = [False]*self.n for v in reversed(vs): if not used[v]: k += 1 _rdfs(v, k) return cmp import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n, m = map(int, input().split()) LR0 = [] LR1 = [] for i in range(n): l, r = map(int, input().split()) LR0.append((l, r)) LR1.append((m-1-r, m-1-l)) scc = SCC(2*n) for i in range(n-1): for j in range(i+1, n): li0, ri0 = LR0[i] li1, ri1 = LR1[i] lj0, rj0 = LR0[j] lj1, rj1 = LR1[j] # 区間がかぶる場合を考える cnt = 0 if min(ri0, rj0) >= max(li0, lj0): # ¬xi ∨ ¬xj # xi ⇒ ¬xj, xj ⇒ ¬xi scc.add_edge(i, n+j) scc.add_edge(j, n+i) cnt += 1 if min(ri0, rj1) >= max(li0, lj1): # ¬xi ∨ xj # xi ⇒ xj, ¬xj ⇒ ¬xi scc.add_edge(i, j) scc.add_edge(n+j, n+i) if min(ri1, rj0) >= max(li1, lj0): # xi ∨ ¬xj # ¬xi ⇒ ¬xj, xj ⇒ xi scc.add_edge(n+i, n+j) scc.add_edge(j, i) cnt += 1 if min(ri1, rj1) >= max(li1, lj1): # xi ∨ xj # ¬xi ⇒ xj, ¬xj ⇒ xi scc.add_edge(n+i, j) scc.add_edge(n+j, i) cnt += 1 if cnt == 4: print('NO') exit() cmp = scc.scc() for i in range(n): if cmp[i] == cmp[n+i]: print('NO') exit() print('YES')