#!/usr/bin/env python3
import heapq


INF = 10 ** 9

class SegTreeX:

    def __init__(self, n):
        k = 1
        while k < n:
            k *= 2
        self.n = k
        self.dat = [0] * (k * 2)
        self.pos = [i - (k - 1) for i in range(k * 2)]


    def update(self, i, x):
        i += self.n - 1
        self.dat[i] = x
        while 0 < i:
            i = (i - 1) // 2
            d1 = self.dat[i * 2 + 1]
            d2 = self.dat[i * 2 + 2]
            if d1 <= d2:
                self.dat[i] = d1
                self.pos[i] = self.pos[i * 2 + 1]
            else:
                self.dat[i] = d2
                self.pos[i] = self.pos[i * 2 + 2]


    def query(self, a, b, k = 0, l = 0, r = -1):
        if r < 0:
            r = self.n
        if r <= a or b <= l:
            return INF, -1
        if a <= l and r <= b:
            return self.dat[k], self.pos[k]
        else:
            vl, pl = self.query(a, b, k * 2 + 1, l, (l + r) // 2)
            vr, pr = self.query(a, b, k * 2 + 2, (l + r) // 2, r)
            if vl <= vr:
                return vl, pl
            else:
                return vr, pr


def solve(n, m, a):


    a.sort()
    ans = 0
    q = []
    ol = -1
    seg = SegTreeX(m + 1)
    for i in range(n):
        li, ri = a[i]
        if li != ol and 0 <= ol:
            while ol < len(q):
                rj = heapq.heappop(q)
                if m < rj:
                    ans += 1
                else:
                    v, p = seg.query(rj, m + 1)
                    if p < 0 or v == 1:
                        ans += 1
                    else:
                        seg.update(p, 1)
        heapq.heappush(q, ri)
        ol = li
    while ol < len(q):
        rj = heapq.heappop(q)
        if m < rj:
            ans += 1
        else:
            v, p = seg.query(rj, m + 1)
            if p < 0 or v == 1:
                ans += 1
            else:
                seg.update(p, 1)

    if ans < n - m:
        ans = n - m

    return ans


def main():
    n, m = input().split()
    n = int(n)
    m = int(m)
    a = []
    for _ in range(n):
        li, ri = input().split()
        li = int(li)
        ri = int(ri)
        a.append((li, ri))

    print(solve(n, m, a))


if __name__ == '__main__':
    main()

