from itertools import accumulate

N, C = list(map(int, input().split()))

V = [[0] * (10 ** 5 + 1) for i in range(C)]



for i in range(N):

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

    s, t, c = s - 1, t - 1, c - 1

    V[c][s] += 1

    V[c][t + 1] -= 1



for c in range(C):

    V[c] = list(accumulate(V[c]))



ans = 0

for i in range(10 ** 5 + 1):

    tmp = 0

    for c in range(C):

        tmp += min(1, V[c][i])

    ans = max(ans, tmp)



print(ans)

from itertools import accumulate

N, C = list(map(int, input().split()))

TimeTable = [[0] * (10 ** 5 + 2) for i in range(C + 1)]

for i in range(N):

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

    TimeTable[c][s] += 1

    TimeTable[c][t + 1] -= 1



for c in range(C + 1):

    TimeTable[c] = list(accumulate(TimeTable[c]))





ans = 0

for i in range(10 ** 5 + 2):

    cnt = 0

    for c in range(C + 1):

        cnt += min(TimeTable[c][i], 1)

    ans = max(ans, cnt)



print(ans)

from itertools import accumulate

N, C = list(map(int, input().split()))
V = [[0] * (10**5 + 1) for i in range(C)]
for i in range(N):
    s, t, c = list(map(int, input().split()))
    s, t, c = s - 1, t - 1, c - 1
    V[c][s] += 1
    V[c][t + 1] -= 1
for c in range(C):
    V[c] = list(accumulate(V[c]))
ans = 0
for i in range(10**5 + 1):
    tmp = 0
    for c in range(C):
        tmp += min(1, V[c][i])
    ans = max(ans, tmp)
print(ans)

from itertools import accumulate

N, C = list(map(int, input().split()))
TimeTable = [[0] * (10**5 + 2) for i in range(C + 1)]
for i in range(N):
    s, t, c = list(map(int, input().split()))
    TimeTable[c][s] += 1
    TimeTable[c][t + 1] -= 1
for c in range(C + 1):
    TimeTable[c] = list(accumulate(TimeTable[c]))
ans = 0
for i in range(10**5 + 2):
    cnt = 0
    for c in range(C + 1):
        cnt += min(TimeTable[c][i], 1)
    ans = max(ans, cnt)
print(ans)

-V = [[0] * (10**5 + 1) for i in range(C)] +TimeTable = [[0] * (10**5 + 2) for i in range(C + 1)] -    s, t, c = s - 1, t - 1, c - 1 -    V[c][s] += 1 -    V[c][t + 1] -= 1 -for c in range(C): -    V[c] = list(accumulate(V[c])) +    TimeTable[c][s] += 1 +    TimeTable[c][t + 1] -= 1 +for c in range(C + 1): +    TimeTable[c] = list(accumulate(TimeTable[c])) -for i in range(10**5 + 1): -    tmp = 0 -    for c in range(C): -        tmp += min(1, V[c][i]) -    ans = max(ans, tmp) +for i in range(10**5 + 2): +    cnt = 0 +    for c in range(C + 1): +        cnt += min(TimeTable[c][i], 1) +    ans = max(ans, cnt)