from heapq import heappop, heappush





def main():

    n, c = list(map(int, input().split()))

    program = [[] for _ in range(c)]

    for _ in range(n):

        s, t, cc = list(map(int, input().split()))

        cc -= 1

        s *= 2

        t *= 2

        program[cc].append([s - 1, t])

    all_p = []

    for i in range(c):

        if len(program[i]) == 0:

            continue

        now = program[i]

        now.sort(key=lambda x: x[1])

        last_begin, last_end = now[0]

        for begin, end in now[1:]:

            if begin + 1 == last_end:

                last_end = end

            else:

                all_p.append([last_begin, last_end, i])

                last_begin = begin

                last_end = end

        all_p.append([last_begin, last_end, i])

    all_p.sort()

    q = [(-1, -1)]

    for begin, end, now_channel in all_p:

        last_end, last_channel = q[0]

        if last_end < begin or now_channel == last_channel:

            heappop(q)

        heappush(q, (end, now_channel))

    print((len(q)))





if __name__ == '__main__':

    main()

from itertools import accumulate





def main():

    n, c = list(map(int, input().split()))

    p = [[] for _ in range(c + 1)]

    for _ in range(n):

        *st, cc = list(map(int, input().split()))

        p[cc].append(st)

    all_p = [0] * (10 ** 5 + 10)

    for pp in p:

        if len(pp) == 0:

            continue

        pp.sort()

        last_start, last_end = pp[0]

        for start, end in pp[1:]:

            if start == last_end:

                last_end = end

            else:

                all_p[last_start - 1] += 1

                all_p[last_end] -= 1

                last_start, last_end = start, end

        all_p[last_start - 1] += 1

        all_p[last_end] -= 1

    print((max(accumulate(all_p))))





if __name__ == '__main__':

    main()

from heapq import heappop, heappush


def main():
    n, c = list(map(int, input().split()))
    program = [[] for _ in range(c)]
    for _ in range(n):
        s, t, cc = list(map(int, input().split()))
        cc -= 1
        s *= 2
        t *= 2
        program[cc].append([s - 1, t])
    all_p = []
    for i in range(c):
        if len(program[i]) == 0:
            continue
        now = program[i]
        now.sort(key=lambda x: x[1])
        last_begin, last_end = now[0]
        for begin, end in now[1:]:
            if begin + 1 == last_end:
                last_end = end
            else:
                all_p.append([last_begin, last_end, i])
                last_begin = begin
                last_end = end
        all_p.append([last_begin, last_end, i])
    all_p.sort()
    q = [(-1, -1)]
    for begin, end, now_channel in all_p:
        last_end, last_channel = q[0]
        if last_end < begin or now_channel == last_channel:
            heappop(q)
        heappush(q, (end, now_channel))
    print((len(q)))


if __name__ == "__main__":
    main()

from itertools import accumulate


def main():
    n, c = list(map(int, input().split()))
    p = [[] for _ in range(c + 1)]
    for _ in range(n):
        *st, cc = list(map(int, input().split()))
        p[cc].append(st)
    all_p = [0] * (10**5 + 10)
    for pp in p:
        if len(pp) == 0:
            continue
        pp.sort()
        last_start, last_end = pp[0]
        for start, end in pp[1:]:
            if start == last_end:
                last_end = end
            else:
                all_p[last_start - 1] += 1
                all_p[last_end] -= 1
                last_start, last_end = start, end
        all_p[last_start - 1] += 1
        all_p[last_end] -= 1
    print((max(accumulate(all_p))))


if __name__ == "__main__":
    main()

-from heapq import heappop, heappush +from itertools import accumulate -    program = [[] for _ in range(c)] +    p = [[] for _ in range(c + 1)] -        s, t, cc = list(map(int, input().split())) -        cc -= 1 -        s *= 2 -        t *= 2 -        program[cc].append([s - 1, t]) -    all_p = [] -    for i in range(c): -        if len(program[i]) == 0: +        *st, cc = list(map(int, input().split())) +        p[cc].append(st) +    all_p = [0] * (10**5 + 10) +    for pp in p: +        if len(pp) == 0: -        now = program[i] -        now.sort(key=lambda x: x[1]) -        last_begin, last_end = now[0] -        for begin, end in now[1:]: -            if begin + 1 == last_end: +        pp.sort() +        last_start, last_end = pp[0] +        for start, end in pp[1:]: +            if start == last_end: -                all_p.append([last_begin, last_end, i]) -                last_begin = begin -                last_end = end -        all_p.append([last_begin, last_end, i]) -    all_p.sort() -    q = [(-1, -1)] -    for begin, end, now_channel in all_p: -        last_end, last_channel = q[0] -        if last_end < begin or now_channel == last_channel: -            heappop(q) -        heappush(q, (end, now_channel)) -    print((len(q))) +                all_p[last_start - 1] += 1 +                all_p[last_end] -= 1 +                last_start, last_end = start, end +        all_p[last_start - 1] += 1 +        all_p[last_end] -= 1 +    print((max(accumulate(all_p))))