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



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



pgs = []

for _ in range(N):

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

    pgs.append((s, t, c))



pgs = sorted(pgs, key=lambda x: (x[2], x[0]))



for i in range(N):

    s, t, c = pgs[i]

    if i >= 1 and pgs[i-1][2] == pgs[i][2] and pgs[i-1][1] == pgs[i][0]:

        imos[s] += 1

        imos[t] -= 1

    else:

        imos[s-1] += 1

        imos[t] -= 1



ans = 0

a = 0

for i in imos:

    a += i

    ans = max(ans, a)



print(ans)

from collections import defaultdict



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



D = defaultdict(list)

for _ in range(N):

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

    D[c-1].append((s, t))



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

for c in range(C):

    D[c].sort(key=lambda x: x[0])



    pt = -1

    for i, (s, t) in enumerate(D[c]):

        if s == pt:

            IMOS[s+1] += 1

            IMOS[t] -= 1

        else:

            IMOS[s-1] += 1

            IMOS[t] -= 1

        pt = t



ans = 0

a = 0

for i in IMOS:

    a += i

    ans = max(ans, a)



print(ans)

N, C = list(map(int, input().split()))
imos = [0] * (10**5 + 1)
pgs = []
for _ in range(N):
    s, t, c = list(map(int, input().split()))
    pgs.append((s, t, c))
pgs = sorted(pgs, key=lambda x: (x[2], x[0]))
for i in range(N):
    s, t, c = pgs[i]
    if i >= 1 and pgs[i - 1][2] == pgs[i][2] and pgs[i - 1][1] == pgs[i][0]:
        imos[s] += 1
        imos[t] -= 1
    else:
        imos[s - 1] += 1
        imos[t] -= 1
ans = 0
a = 0
for i in imos:
    a += i
    ans = max(ans, a)
print(ans)

from collections import defaultdict

N, C = list(map(int, input().split()))
D = defaultdict(list)
for _ in range(N):
    s, t, c = list(map(int, input().split()))
    D[c - 1].append((s, t))
IMOS = [0] * (10**5 + 2)
for c in range(C):
    D[c].sort(key=lambda x: x[0])
    pt = -1
    for i, (s, t) in enumerate(D[c]):
        if s == pt:
            IMOS[s + 1] += 1
            IMOS[t] -= 1
        else:
            IMOS[s - 1] += 1
            IMOS[t] -= 1
        pt = t
ans = 0
a = 0
for i in IMOS:
    a += i
    ans = max(ans, a)
print(ans)

+from collections import defaultdict + -imos = [0] * (10**5 + 1) -pgs = [] +D = defaultdict(list) -    pgs.append((s, t, c)) -pgs = sorted(pgs, key=lambda x: (x[2], x[0])) -for i in range(N): -    s, t, c = pgs[i] -    if i >= 1 and pgs[i - 1][2] == pgs[i][2] and pgs[i - 1][1] == pgs[i][0]: -        imos[s] += 1 -        imos[t] -= 1 -    else: -        imos[s - 1] += 1 -        imos[t] -= 1 +    D[c - 1].append((s, t)) +IMOS = [0] * (10**5 + 2) +for c in range(C): +    D[c].sort(key=lambda x: x[0]) +    pt = -1 +    for i, (s, t) in enumerate(D[c]): +        if s == pt: +            IMOS[s + 1] += 1 +            IMOS[t] -= 1 +        else: +            IMOS[s - 1] += 1 +            IMOS[t] -= 1 +        pt = t -for i in imos: +for i in IMOS: