# -*- coding: utf-8 -*-

from operator import itemgetter



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

record = []

for _ in range(N):

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

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

record.sort(key=itemgetter(1,0,2))



def can_record(k):

    slots = [(-1,-1)]*k  # (end_time, channel)



    for r in record:

        idx = -1

        t = -1

        for i in range(k):

            end_time, channel = slots[i]

            if channel==r[2]:

                if end_time<=r[0]:

                    if t<=end_time:

                        t = end_time

                        idx = i

            else:

                if end_time<r[0]:

                    if t<=end_time:

                        t = end_time

                        idx = i

        if idx==-1:

            return False

        else:

            slots[idx] = (r[1],r[2])

    return True



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

    if can_record(k):

        print(k)

        break

# -*- coding: utf-8 -*-

from operator import itemgetter



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

T = 0

record = []

for _ in range(N):

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

    T = max(T, t)

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

record.sort(key=itemgetter(2,0,1))



tl = [0]*(T+1)

curr_channel = None

for r in record:

    s,t,c = r

    if curr_channel==c:

        if curr_time==s:

            tl[s] += 1

            tl[t] -= 1

        else:

            tl[s-1] += 1

            tl[t] -= 1

        curr_time = t

    else:

        tl[s-1] += 1

        tl[t] -= 1

        curr_channel = c

        curr_time = t



s = 0

res = 0

for t in tl:

    s += t

    res = max(res, s)

print(res)

# -*- coding: utf-8 -*-
from operator import itemgetter

N, C = list(map(int, input().split()))
record = []
for _ in range(N):
    s, t, c = list(map(int, input().split()))
    record.append((s, t, c))
record.sort(key=itemgetter(1, 0, 2))


def can_record(k):
    slots = [(-1, -1)] * k  # (end_time, channel)
    for r in record:
        idx = -1
        t = -1
        for i in range(k):
            end_time, channel = slots[i]
            if channel == r[2]:
                if end_time <= r[0]:
                    if t <= end_time:
                        t = end_time
                        idx = i
            else:
                if end_time < r[0]:
                    if t <= end_time:
                        t = end_time
                        idx = i
        if idx == -1:
            return False
        else:
            slots[idx] = (r[1], r[2])
    return True


for k in range(1, C + 1):
    if can_record(k):
        print(k)
        break

# -*- coding: utf-8 -*-
from operator import itemgetter

N, C = list(map(int, input().split()))
T = 0
record = []
for _ in range(N):
    s, t, c = list(map(int, input().split()))
    T = max(T, t)
    record.append((s, t, c))
record.sort(key=itemgetter(2, 0, 1))
tl = [0] * (T + 1)
curr_channel = None
for r in record:
    s, t, c = r
    if curr_channel == c:
        if curr_time == s:
            tl[s] += 1
            tl[t] -= 1
        else:
            tl[s - 1] += 1
            tl[t] -= 1
        curr_time = t
    else:
        tl[s - 1] += 1
        tl[t] -= 1
        curr_channel = c
        curr_time = t
s = 0
res = 0
for t in tl:
    s += t
    res = max(res, s)
print(res)

+T = 0 +    T = max(T, t) -record.sort(key=itemgetter(1, 0, 2)) - - -def can_record(k): -    slots = [(-1, -1)] * k  # (end_time, channel) -    for r in record: -        idx = -1 -        t = -1 -        for i in range(k): -            end_time, channel = slots[i] -            if channel == r[2]: -                if end_time <= r[0]: -                    if t <= end_time: -                        t = end_time -                        idx = i -            else: -                if end_time < r[0]: -                    if t <= end_time: -                        t = end_time -                        idx = i -        if idx == -1: -            return False +record.sort(key=itemgetter(2, 0, 1)) +tl = [0] * (T + 1) +curr_channel = None +for r in record: +    s, t, c = r +    if curr_channel == c: +        if curr_time == s: +            tl[s] += 1 +            tl[t] -= 1 -            slots[idx] = (r[1], r[2]) -    return True - - -for k in range(1, C + 1): -    if can_record(k): -        print(k) -        break +            tl[s - 1] += 1 +            tl[t] -= 1 +        curr_time = t +    else: +        tl[s - 1] += 1 +        tl[t] -= 1 +        curr_channel = c +        curr_time = t +s = 0 +res = 0 +for t in tl: +    s += t +    res = max(res, s) +print(res)