def inpl(): return tuple(map(int, input().split()))



N, C = inpl()

P = sorted([inpl() for _ in range(N)])



R = [[[-1, 0, -1]] for _ in range(30)]

for s, t, c in P:

    i = 0

    # 連続録画を探す

    sr = [i for i in range(30) if R[i][-1][2] == c and R[i][-1][1] <= s]

    if sr:

        R[min(sr)].append([s, t, c])

    else:

        r = [i for i in range(30) if R[i][-1][1] <= s - 0.5]

        R[min(r)].append([s, t, c])



for i in range(30):

    if len(R[i]) == 1:

        print(i)

        break

else:

    print((30))
# -*- coding: utf-8 -*-

from itertools import accumulate

def inpl(): return tuple(map(int, input().split()))



N, C = inpl()

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



for _ in range(N):

    s, t, c = inpl()

    P[c-1].append((2*s, 2*t))



S = [0 for _ in range(2*10**5 + 3)]

for p in P:

    if len(p) == 0:

        continue

    p2 = []

    p = sorted(p)

    s, t = p[0]

    for i in range(1, len(p)):

        if t == p[i][0]:

            t = p[i][1]

        else:

            S[s-1] += 1

            S[t+1] -= 1

            s, t = p[i]

    S[s-1] += 1

    S[t+1] -= 1



print((max(accumulate(S))))
def inpl():
    return tuple(map(int, input().split()))


N, C = inpl()
P = sorted([inpl() for _ in range(N)])
R = [[[-1, 0, -1]] for _ in range(30)]
for s, t, c in P:
    i = 0
    # 連続録画を探す
    sr = [i for i in range(30) if R[i][-1][2] == c and R[i][-1][1] <= s]
    if sr:
        R[min(sr)].append([s, t, c])
    else:
        r = [i for i in range(30) if R[i][-1][1] <= s - 0.5]
        R[min(r)].append([s, t, c])
for i in range(30):
    if len(R[i]) == 1:
        print(i)
        break
else:
    print((30))

# -*- coding: utf-8 -*-
from itertools import accumulate


def inpl():
    return tuple(map(int, input().split()))


N, C = inpl()
P = [[] for _ in range(C)]
for _ in range(N):
    s, t, c = inpl()
    P[c - 1].append((2 * s, 2 * t))
S = [0 for _ in range(2 * 10**5 + 3)]
for p in P:
    if len(p) == 0:
        continue
    p2 = []
    p = sorted(p)
    s, t = p[0]
    for i in range(1, len(p)):
        if t == p[i][0]:
            t = p[i][1]
        else:
            S[s - 1] += 1
            S[t + 1] -= 1
            s, t = p[i]
    S[s - 1] += 1
    S[t + 1] -= 1
print((max(accumulate(S))))

+# -*- coding: utf-8 -*- +from itertools import accumulate + + -P = sorted([inpl() for _ in range(N)]) -R = [[[-1, 0, -1]] for _ in range(30)] -for s, t, c in P: -    i = 0 -    # 連続録画を探す -    sr = [i for i in range(30) if R[i][-1][2] == c and R[i][-1][1] <= s] -    if sr: -        R[min(sr)].append([s, t, c]) -    else: -        r = [i for i in range(30) if R[i][-1][1] <= s - 0.5] -        R[min(r)].append([s, t, c]) -for i in range(30): -    if len(R[i]) == 1: -        print(i) -        break -else: -    print((30)) +P = [[] for _ in range(C)] +for _ in range(N): +    s, t, c = inpl() +    P[c - 1].append((2 * s, 2 * t)) +S = [0 for _ in range(2 * 10**5 + 3)] +for p in P: +    if len(p) == 0: +        continue +    p2 = [] +    p = sorted(p) +    s, t = p[0] +    for i in range(1, len(p)): +        if t == p[i][0]: +            t = p[i][1] +        else: +            S[s - 1] += 1 +            S[t + 1] -= 1 +            s, t = p[i] +    S[s - 1] += 1 +    S[t + 1] -= 1 +print((max(accumulate(S))))