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

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

L.sort()

tmp = [[] for _ in range(C)]

for s, t, c in L:

    if tmp[c - 1]:

        if tmp[c - 1][-1][1] == s:

            tmp[c - 1][-1][1] = t

            continue

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

l = []

for v in tmp:

    for i in v:

        l.append(i)

l.sort()



r = [0] * C

for s, t in l:

    for i in range(C):

        if r[i] < s:

            r[i] = t

            break

print((sum(1 for i in r if i)))            
# 解説 imos

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

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

m = 2 * 10 ** 5 + 2

S = [0] * m

for x in range(1, C + 1):

    T = [0] * m

    for s, t, c in L:

        if c == x:

            # 始点を奇数, 終点を偶数にするのうまい

            T[2 * s - 1] += 1

            T[2 * t] -= 1

    for i in range(1, m):

        T[i] += T[i - 1]

    for i in range(m):

        if T[i] > 0:

            S[i] += 1

print((max(S)))
n, C = list(map(int, input().split()))
L = [tuple(map(int, input().split())) for _ in range(n)]
L.sort()
tmp = [[] for _ in range(C)]
for s, t, c in L:
    if tmp[c - 1]:
        if tmp[c - 1][-1][1] == s:
            tmp[c - 1][-1][1] = t
            continue
    tmp[c - 1].append([s, t])
l = []
for v in tmp:
    for i in v:
        l.append(i)
l.sort()
r = [0] * C
for s, t in l:
    for i in range(C):
        if r[i] < s:
            r[i] = t
            break
print((sum(1 for i in r if i)))

# 解説 imos
n, C = list(map(int, input().split()))
L = [tuple(map(int, input().split())) for _ in range(n)]
m = 2 * 10**5 + 2
S = [0] * m
for x in range(1, C + 1):
    T = [0] * m
    for s, t, c in L:
        if c == x:
            # 始点を奇数, 終点を偶数にするのうまい
            T[2 * s - 1] += 1
            T[2 * t] -= 1
    for i in range(1, m):
        T[i] += T[i - 1]
    for i in range(m):
        if T[i] > 0:
            S[i] += 1
print((max(S)))

+# 解説 imos -L.sort() -tmp = [[] for _ in range(C)] -for s, t, c in L: -    if tmp[c - 1]: -        if tmp[c - 1][-1][1] == s: -            tmp[c - 1][-1][1] = t -            continue -    tmp[c - 1].append([s, t]) -l = [] -for v in tmp: -    for i in v: -        l.append(i) -l.sort() -r = [0] * C -for s, t in l: -    for i in range(C): -        if r[i] < s: -            r[i] = t -            break -print((sum(1 for i in r if i))) +m = 2 * 10**5 + 2 +S = [0] * m +for x in range(1, C + 1): +    T = [0] * m +    for s, t, c in L: +        if c == x: +            # 始点を奇数, 終点を偶数にするのうまい +            T[2 * s - 1] += 1 +            T[2 * t] -= 1 +    for i in range(1, m): +        T[i] += T[i - 1] +    for i in range(m): +        if T[i] > 0: +            S[i] += 1 +print((max(S)))