from collections import defaultdict

from heapq import heapreplace, heappush



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

programs = defaultdict(list)

for _ in range(n):

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

    programs[c].append((s, t))



combined = []

for c, p in list(programs.items()):

    p.sort()

    ps, pt = p[0]

    for s, t in p[1:]:

        if pt == s:

            pt = t

        else:

            combined.append((ps, pt, c))

            ps, pt = s, t

    combined.append((ps, pt, c))

combined.sort()



recorders = [(-1, None)]

for s, t, c in combined:

    end, channel = recorders[0]

    if end < s or c == channel:

        heapreplace(recorders, (t, c))

    else:

        heappush(recorders, (t, c))

print((len(recorders)))

from collections import defaultdict

from itertools import accumulate



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

programs = defaultdict(list)

for _ in range(n):

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

    programs[c].append((s, t))



imos = [0] * (2 * 10 ** 5 + 2)

for c, p in list(programs.items()):

    p.sort()

    ps, pt = p[0]

    for s, t in p[1:]:

        if pt == s:

            pt = t

        else:

            imos[2 * ps - 1] += 1

            imos[2 * pt + 1] -= 1

            ps, pt = s, t

    imos[2 * ps - 1] += 1

    imos[2 * pt + 1] -= 1



print((max(accumulate(imos))))

from collections import defaultdict
from heapq import heapreplace, heappush

n, v = list(map(int, input().split()))
programs = defaultdict(list)
for _ in range(n):
    s, t, c = list(map(int, input().split()))
    programs[c].append((s, t))
combined = []
for c, p in list(programs.items()):
    p.sort()
    ps, pt = p[0]
    for s, t in p[1:]:
        if pt == s:
            pt = t
        else:
            combined.append((ps, pt, c))
            ps, pt = s, t
    combined.append((ps, pt, c))
combined.sort()
recorders = [(-1, None)]
for s, t, c in combined:
    end, channel = recorders[0]
    if end < s or c == channel:
        heapreplace(recorders, (t, c))
    else:
        heappush(recorders, (t, c))
print((len(recorders)))

from collections import defaultdict
from itertools import accumulate

n, v = list(map(int, input().split()))
programs = defaultdict(list)
for _ in range(n):
    s, t, c = list(map(int, input().split()))
    programs[c].append((s, t))
imos = [0] * (2 * 10**5 + 2)
for c, p in list(programs.items()):
    p.sort()
    ps, pt = p[0]
    for s, t in p[1:]:
        if pt == s:
            pt = t
        else:
            imos[2 * ps - 1] += 1
            imos[2 * pt + 1] -= 1
            ps, pt = s, t
    imos[2 * ps - 1] += 1
    imos[2 * pt + 1] -= 1
print((max(accumulate(imos))))

-from heapq import heapreplace, heappush +from itertools import accumulate -combined = [] +imos = [0] * (2 * 10**5 + 2) -            combined.append((ps, pt, c)) +            imos[2 * ps - 1] += 1 +            imos[2 * pt + 1] -= 1 -    combined.append((ps, pt, c)) -combined.sort() -recorders = [(-1, None)] -for s, t, c in combined: -    end, channel = recorders[0] -    if end < s or c == channel: -        heapreplace(recorders, (t, c)) -    else: -        heappush(recorders, (t, c)) -print((len(recorders))) +    imos[2 * ps - 1] += 1 +    imos[2 * pt + 1] -= 1 +print((max(accumulate(imos))))