N,M = map(int,input().split())
span = []
for _ in range(N):
    l,r = map(int,input().split())
    s = r
    t = M+l
    span.append((s,t))

span.sort()
cnt = 0
tmp = -1

for s,t in span:
    if tmp < s:
        tmp = s
    elif tmp+1<=t:
        tmp += 1
    else:
        cnt += 1

print(cnt)

