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

TV = [[0]*(2*10**5) for i in range(C)]



for i in range(N):

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

    TV[c-1][2*s-2] += 1

    TV[c-1][2*t-1] -= 1



for i in range(C):

    for j in range(1, 2*10**5):

        TV[i][j] = TV[i][j]+TV[i][j-1]



for i in range(C):

    for j in range(1, 2*10**5):

        TV[i][j] = min(1, TV[i][j])



ans = 0

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

    tmp = 0

    for j in range(C):

        tmp += TV[j][i]

    ans = max(ans, tmp)

print(ans)

from itertools import accumulate

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

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

for i in range(N):

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

    c = c - 1

    G[c][s - 1] += 1

    G[c][t] -= 1



for i in range(C):

    G[i] = list(accumulate(G[i]))



ans = 0

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

    tmp = 0

    for c in range(C):

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

    ans = max(ans, tmp)



print(ans)

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

from itertools import accumulate

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

+from itertools import accumulate + -TV = [[0] * (2 * 10**5) for i in range(C)] +G = [[0] * (10**5 + 1) for i in range(C)] -    TV[c - 1][2 * s - 2] += 1 -    TV[c - 1][2 * t - 1] -= 1 +    c = c - 1 +    G[c][s - 1] += 1 +    G[c][t] -= 1 -    for j in range(1, 2 * 10**5): -        TV[i][j] = TV[i][j] + TV[i][j - 1] -for i in range(C): -    for j in range(1, 2 * 10**5): -        TV[i][j] = min(1, TV[i][j]) +    G[i] = list(accumulate(G[i])) -for i in range(2 * 10**5): +for i in range(10**5 + 1): -    for j in range(C): -        tmp += TV[j][i] +    for c in range(C): +        tmp += min(1, G[c][i])