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



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



for i in range(N):

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

    P[c-1].append([s,"S"])

    P[c-1].append([t,"T"])



P = [sorted(sorted(P[i],key=lambda x:x[1]),key=lambda x: x[0]) for i in range(C)]

#print(P)

P2 = []



for i in range(C):

    for j in range(len(P[i])):

        if P[i][j][1]=="T":

            if j!=0:

                if P[i][j][0]!=P[i][j-1][0]:

                    P2.append(P[i][j])

            else:

                P2.append(P[i][j])

        else:

            if j!=len(P[i])-1:

                if P[i][j][0]!=P[i][j+1][0]:

                    P2.append([P[i][j][0]-0.5,P[i][j][1]])

            else:

                P2.append([P[i][j][0]-0.5,P[i][j][1]])



P = P2

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



count=0

max_count=0

s_buf = 0

t_buf = 0



prev = -1

for i in range(len(P)):

    if prev!=P[i][0]:

        prev=P[i][0]

        count+=s_buf-t_buf

        s_buf=0

        t_buf=0

        max_count=max(count,max_count)

    if P[i][1]=="S":

        s_buf+=1

    else:

        t_buf+=1

#print(P)

count+=s_buf-t_buf

max_count=max(count,max_count)



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



program_list = []



for i in range(N):

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

    program_list.append((s-0.5,"s",c-1))

    program_list.append((t,"t",c-1))



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



c_list=[0 for i in range(C)]

count_list=[0 for i in range(C)]



max_num=0

for i in range(2*N):

    if program_list[i][1]=="s":

        c = program_list[i][2]

        count_list[c]+=1

        c_list[c] = min(1,count_list[c])

        max_num=max(sum(c_list),max_num)

    else:

        c = program_list[i][2]

        count_list[c]-=1

        c_list[c] = min(1,count_list[c])



print(max_num)
N, C = list(map(int, input().split()))
P = [[] for i in range(C)]
for i in range(N):
    s, t, c = list(map(int, input().split()))
    P[c - 1].append([s, "S"])
    P[c - 1].append([t, "T"])
P = [sorted(sorted(P[i], key=lambda x: x[1]), key=lambda x: x[0]) for i in range(C)]
# print(P)
P2 = []
for i in range(C):
    for j in range(len(P[i])):
        if P[i][j][1] == "T":
            if j != 0:
                if P[i][j][0] != P[i][j - 1][0]:
                    P2.append(P[i][j])
            else:
                P2.append(P[i][j])
        else:
            if j != len(P[i]) - 1:
                if P[i][j][0] != P[i][j + 1][0]:
                    P2.append([P[i][j][0] - 0.5, P[i][j][1]])
            else:
                P2.append([P[i][j][0] - 0.5, P[i][j][1]])
P = P2
P = sorted(P, key=lambda x: x[0])
count = 0
max_count = 0
s_buf = 0
t_buf = 0
prev = -1
for i in range(len(P)):
    if prev != P[i][0]:
        prev = P[i][0]
        count += s_buf - t_buf
        s_buf = 0
        t_buf = 0
        max_count = max(count, max_count)
    if P[i][1] == "S":
        s_buf += 1
    else:
        t_buf += 1
# print(P)
count += s_buf - t_buf
max_count = max(count, max_count)
print(max_count)

N, C = list(map(int, input().split()))
program_list = []
for i in range(N):
    s, t, c = list(map(int, input().split()))
    program_list.append((s - 0.5, "s", c - 1))
    program_list.append((t, "t", c - 1))
program_list.sort(key=lambda x: x[0])
c_list = [0 for i in range(C)]
count_list = [0 for i in range(C)]
max_num = 0
for i in range(2 * N):
    if program_list[i][1] == "s":
        c = program_list[i][2]
        count_list[c] += 1
        c_list[c] = min(1, count_list[c])
        max_num = max(sum(c_list), max_num)
    else:
        c = program_list[i][2]
        count_list[c] -= 1
        c_list[c] = min(1, count_list[c])
print(max_num)

-P = [[] for i in range(C)] +program_list = [] -    P[c - 1].append([s, "S"]) -    P[c - 1].append([t, "T"]) -P = [sorted(sorted(P[i], key=lambda x: x[1]), key=lambda x: x[0]) for i in range(C)] -# print(P) -P2 = [] -for i in range(C): -    for j in range(len(P[i])): -        if P[i][j][1] == "T": -            if j != 0: -                if P[i][j][0] != P[i][j - 1][0]: -                    P2.append(P[i][j]) -            else: -                P2.append(P[i][j]) -        else: -            if j != len(P[i]) - 1: -                if P[i][j][0] != P[i][j + 1][0]: -                    P2.append([P[i][j][0] - 0.5, P[i][j][1]]) -            else: -                P2.append([P[i][j][0] - 0.5, P[i][j][1]]) -P = P2 -P = sorted(P, key=lambda x: x[0]) -count = 0 -max_count = 0 -s_buf = 0 -t_buf = 0 -prev = -1 -for i in range(len(P)): -    if prev != P[i][0]: -        prev = P[i][0] -        count += s_buf - t_buf -        s_buf = 0 -        t_buf = 0 -        max_count = max(count, max_count) -    if P[i][1] == "S": -        s_buf += 1 +    program_list.append((s - 0.5, "s", c - 1)) +    program_list.append((t, "t", c - 1)) +program_list.sort(key=lambda x: x[0]) +c_list = [0 for i in range(C)] +count_list = [0 for i in range(C)] +max_num = 0 +for i in range(2 * N): +    if program_list[i][1] == "s": +        c = program_list[i][2] +        count_list[c] += 1 +        c_list[c] = min(1, count_list[c]) +        max_num = max(sum(c_list), max_num) -        t_buf += 1 -# print(P) -count += s_buf - t_buf -max_count = max(count, max_count) -print(max_count) +        c = program_list[i][2] +        count_list[c] -= 1 +        c_list[c] = min(1, count_list[c]) +print(max_num)