import sys #input = sys.stdin.readline #文字列につけてはダメ input = sys.stdin.buffer.readline #文字列につけてはダメ #sys.setrecursionlimit(1000000) #import bisect #import itertools #import random #from heapq import heapify, heappop, heappush #from collections import defaultdict #from collections import deque #import copy #import math #from functools import lru_cache #MOD = pow(10,9) + 7 #MOD = 998244353 #https://atcoder.jp/contests/practice2/submissions/17674275 class scc_graph: def __init__(self, N): self.N = N self.edges = [] def csr(self): start = [0]*(self.N+1) elist = [0]*len(self.edges) for v, w in self.edges: start[v+1] += 1 for i in range(1, self.N+1): start[i] += start[i-1] counter = start.copy() for v, w in self.edges: elist[counter[v]] = w counter[v] += 1 self.start = start self.elist = elist def add_edge(self, v, w): self.edges.append((v, w)) def scc_ids(self): self.csr() N = self.N now_ord = group_num = 0 visited = [] low = [0]*N order = [-1]*N ids = [0]*N parent = [-1]*N stack = [] for i in range(N): if order[i] == -1: stack.append(~i) stack.append(i) while stack: v = stack.pop() if v >= 0: if order[v] == -1: low[v] = order[v] = now_ord now_ord += 1 visited.append(v) for i in range(self.start[v], self.start[v+1]): to = self.elist[i] if order[to] == -1: stack.append(~to) stack.append(to) parent[to] = v else: low[v] = min(low[v], order[to]) else: v = ~v if low[v] == order[v]: while True: u = visited.pop() order[u] = N ids[u] = group_num if u == v: break group_num += 1 if parent[v] != -1: low[parent[v]] = min(low[parent[v]], low[v]) for i, x in enumerate(ids): ids[i] = group_num-1-x return group_num, ids def scc(self): group_num, ids = self.scc_ids() groups = [[] for _ in range(group_num)] for i, x in enumerate(ids): groups[x].append(i) return groups class two_sat: def __init__(self, N): self.N = N self.answer = [] self.scc = scc_graph(2*N) def add_clause(self, i, f, j, g): #f,g = 0/1 (True/False) # assert 0 <= i < self.N # assert 0 <= j < self.N self.scc.add_edge(2*i+(f == 0), 2*j+(g == 1)) self.scc.add_edge(2*j+(g == 0), 2*i+(f == 1)) def satisfiable(self): #これがTrueならts.answerで満たす場合の組み合わせを出力可能 _, ids = self.scc.scc_ids() self.answer.clear() for i in range(self.N): if ids[2 * i] == ids[2 * i + 1]: self.answer.clear() return False self.answer.append(ids[2*i] < ids[2*i+1]) return True def main(): N,M = map(int,input().split()) L = []; R = [] for i in range(N): l,r = map(int,input().split()) #0-index L.append(l) R.append(r) ts = two_sat(N) for i in range(N): #全てのペアをチェックしてOverlapするところが一か所でもあったらダメ li0, ri0 = L[i], R[i] li1, ri1 = M-1 - ri0, M-1 - li0 for j in range(i+1,N): lj0, rj0 = L[j], R[j] lj1, rj1 = M-1 - rj0, M-1 - lj0 f1 = not (ri0 < lj0 or rj0 < li0) f2 = not (M - 1 - li0 < lj0 or rj0 < M - 1 - ri0) #print(li0, ri0, li1, ri1) #print(lj0, rj0, lj1, rj1) #枝刈必須!! if f1 and f2: print('NO');exit() if f1: #0,0が被るつまり1,1も被るのでどちらか ts.add_clause(i, 0, i+1, 0) ts.add_clause(i, 1, i+1, 1) if f2: #0,1が被るつまり1,0も被るのでどちらか ts.add_clause(i, 0, i+1, 1) ts.add_clause(i, 1, i+1, 0) if ts.satisfiable(): print('YES') else: print('NO') if __name__ == '__main__': main()