import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

# 区間加算、区間最大
class LazySeg:
    def __init__(self, aa):
        inf = 10 ** 16
        n = 1 << (len(aa) - 1).bit_length()
        tree = [-inf] * (2 * n - 1)
        lazy = [0] * (2 * n - 1)
        tree[n - 1:n - 1 + len(aa)] = aa
        for u in range(n - 2, -1, -1):
            tree[u] = max(tree[u * 2 + 1], tree[u * 2 + 2])
        self.tree = tree
        self.lazy = lazy
        self.n = n
        self.inf = inf

    def prop(self, u, l, r):
        self.tree[u] += self.lazy[u]
        if l + 1 < r:
            self.lazy[u * 2 + 1] += self.lazy[u]
            self.lazy[u * 2 + 2] += self.lazy[u]
        self.lazy[u] = 0

    def add(self, l, r, a, u=0, tl=0, tr=-1):
        if tr == -1: tr = self.n
        if r <= tl or tr <= l: return
        if l <= tl and tr <= r:
            self.lazy[u] += a
            self.prop(u, tl, tr)
            return
        tm = (tl + tr) // 2
        self.prop(u, tl, tr)
        self.add(l, r, a, u * 2 + 1, tl, tm)
        self.add(l, r, a, u * 2 + 2, tm, tr)
        self.tree[u] = max(self.tree[u * 2 + 1], self.tree[u * 2 + 2])

    def max(self, l, r, u=0, tl=0, tr=-1):
        res = -self.inf
        if tr == -1: tr = self.n
        if r <= tl or tr <= l: return res
        self.prop(u, tl, tr)
        if l <= tl and tr <= r:
            return self.tree[u]
        tm = (tl + tr) // 2
        ret = self.max(l, r, u * 2 + 1, tl, tm)
        if ret > res: res = ret
        ret = self.max(l, r, u * 2 + 2, tm, tr)
        if ret > res: res = ret
        return res

def main():
    n,m=MI()
    lr=[LI() for _ in range(n)]
    lr.sort()
    #print(lr)
    aa=list(range(-m,1))
    st=LazySeg(aa)
    ans=max(n-m,0)
    for i,[l,r] in enumerate(lr):
        st.add(0,r,1)
        if i+1<n and lr[i+1][0]==l:continue
        #print(st.max(0,m+1),l)
        over=st.max(0,m+1)-l
        if over>ans:ans=over
    print(ans)

main()