from heapq import heapreplace, heappush



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

programs = [tuple(map(int, input().split())) for _ in range(n)]

programs.sort()

tmp = [None] * v

combined = []

for s, t, c in programs:

    c -= 1

    prev = tmp[c]

    if prev is not None:

        ps, pt, pc = prev

        if pt == s:

            tmp[c] = (ps, t, c)

        else:

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

            tmp[c] = (s, t, c)

    else:

        tmp[c] = (s, t, c)

for prev in tmp:

    if prev is not None:

        combined.append(prev)

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 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 heapq import heapreplace, heappush

n, v = list(map(int, input().split()))
programs = [tuple(map(int, input().split())) for _ in range(n)]
programs.sort()
tmp = [None] * v
combined = []
for s, t, c in programs:
    c -= 1
    prev = tmp[c]
    if prev is not None:
        ps, pt, pc = prev
        if pt == s:
            tmp[c] = (ps, t, c)
        else:
            combined.append((ps, pt, pc))
            tmp[c] = (s, t, c)
    else:
        tmp[c] = (s, t, c)
for prev in tmp:
    if prev is not None:
        combined.append(prev)
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 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 -programs = [tuple(map(int, input().split())) for _ in range(n)] -programs.sort() -tmp = [None] * v +programs = defaultdict(list) +for _ in range(n): +    s, t, c = list(map(int, input().split())) +    programs[c].append((s, t)) -for s, t, c in programs: -    c -= 1 -    prev = tmp[c] -    if prev is not None: -        ps, pt, pc = prev +for c, p in list(programs.items()): +    p.sort() +    ps, pt = p[0] +    for s, t in p[1:]: -            tmp[c] = (ps, t, c) +            pt = t -            combined.append((ps, pt, pc)) -            tmp[c] = (s, t, c) -    else: -        tmp[c] = (s, t, c) -for prev in tmp: -    if prev is not None: -        combined.append(prev) +            combined.append((ps, pt, c)) +            ps, pt = s, t +    combined.append((ps, pt, c))