import collections

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

a=collections.defaultdict(list)



max_t=0

for i in range(N):

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

	a[c].append((s,t))

	max_t=max(max_t,t)



[a[i].sort() for i in list(a.keys())]

#print a

#print max_t



b=collections.defaultdict(list)





for i,j in list(a.items()):

	start=0

	end=0

	for k in j:

		if start==0 and end==0:

			start=k[0]-1

			end=k[1]

			continue

		elif k[0]<=end:

			end=k[1]

		else:

			b[i].append((start,end))

			start=k[0]-1

			end=k[1]

	else:

		b[i].append((start,end))		



#print "# b"

#print b



c=[0 for i in range(max_t+2)]



for i in list(b.values()):

	for j,k in i:

		#print j,1,k+1,-1

		c[j]+=1

		c[k]-=1

#print c



ans=0

sum=0

for i in c:

	sum+=i

	ans=max(ans,sum)



print(ans)





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

import sys

from collections import deque



N,C=list(map(int, sys.stdin.readline().split())) 

stc=[ list(map(int, sys.stdin.readline().split())) for _ in range(N)]

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

max_t=max(stc, key=(lambda x: x[1]))[1]



channel=[ deque() for _ in range(C+1) ]



for s,t,c in stc:

    try:

        prev_s,prev_t=channel[c].pop()

        if prev_t==s:

            channel[c].append((prev_s,t))

        else:

            channel[c].append((prev_s,prev_t))

            channel[c].append((s,t))

    except:

        channel[c].append((s,t))





T=[ 0 for _ in range(max_t+1) ] #時間軸



c=1

for c in range(1,C+1):  #チャンネル

    while channel[c]:

        s,t=channel[c].pop()

        for i in range(s,t+1):

            T[i]+=1



print(max(T))

import collections

N, C = list(map(int, input().split()))
a = collections.defaultdict(list)
max_t = 0
for i in range(N):
    s, t, c = list(map(int, input().split()))
    a[c].append((s, t))
    max_t = max(max_t, t)
[a[i].sort() for i in list(a.keys())]
# print a
# print max_t
b = collections.defaultdict(list)
for i, j in list(a.items()):
    start = 0
    end = 0
    for k in j:
        if start == 0 and end == 0:
            start = k[0] - 1
            end = k[1]
            continue
        elif k[0] <= end:
            end = k[1]
        else:
            b[i].append((start, end))
            start = k[0] - 1
            end = k[1]
    else:
        b[i].append((start, end))
# print "# b"
# print b
c = [0 for i in range(max_t + 2)]
for i in list(b.values()):
    for j, k in i:
        # print j,1,k+1,-1
        c[j] += 1
        c[k] -= 1
# print c
ans = 0
sum = 0
for i in c:
    sum += i
    ans = max(ans, sum)
print(ans)

# -*- coding: utf-8 -*-
import sys
from collections import deque

N, C = list(map(int, sys.stdin.readline().split()))
stc = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
stc.sort(key=lambda x: (x[0]))
max_t = max(stc, key=(lambda x: x[1]))[1]
channel = [deque() for _ in range(C + 1)]
for s, t, c in stc:
    try:
        prev_s, prev_t = channel[c].pop()
        if prev_t == s:
            channel[c].append((prev_s, t))
        else:
            channel[c].append((prev_s, prev_t))
            channel[c].append((s, t))
    except:
        channel[c].append((s, t))
T = [0 for _ in range(max_t + 1)]  # 時間軸
c = 1
for c in range(1, C + 1):  # チャンネル
    while channel[c]:
        s, t = channel[c].pop()
        for i in range(s, t + 1):
            T[i] += 1
print(max(T))

-import collections +# -*- coding: utf-8 -*- +import sys +from collections import deque -N, C = list(map(int, input().split())) -a = collections.defaultdict(list) -max_t = 0 -for i in range(N): -    s, t, c = list(map(int, input().split())) -    a[c].append((s, t)) -    max_t = max(max_t, t) -[a[i].sort() for i in list(a.keys())] -# print a -# print max_t -b = collections.defaultdict(list) -for i, j in list(a.items()): -    start = 0 -    end = 0 -    for k in j: -        if start == 0 and end == 0: -            start = k[0] - 1 -            end = k[1] -            continue -        elif k[0] <= end: -            end = k[1] +N, C = list(map(int, sys.stdin.readline().split())) +stc = [list(map(int, sys.stdin.readline().split())) for _ in range(N)] +stc.sort(key=lambda x: (x[0])) +max_t = max(stc, key=(lambda x: x[1]))[1] +channel = [deque() for _ in range(C + 1)] +for s, t, c in stc: +    try: +        prev_s, prev_t = channel[c].pop() +        if prev_t == s: +            channel[c].append((prev_s, t)) -            b[i].append((start, end)) -            start = k[0] - 1 -            end = k[1] -    else: -        b[i].append((start, end)) -# print "# b" -# print b -c = [0 for i in range(max_t + 2)] -for i in list(b.values()): -    for j, k in i: -        # print j,1,k+1,-1 -        c[j] += 1 -        c[k] -= 1 -# print c -ans = 0 -sum = 0 -for i in c: -    sum += i -    ans = max(ans, sum) -print(ans) +            channel[c].append((prev_s, prev_t)) +            channel[c].append((s, t)) +    except: +        channel[c].append((s, t)) +T = [0 for _ in range(max_t + 1)]  # 時間軸 +c = 1 +for c in range(1, C + 1):  # チャンネル +    while channel[c]: +        s, t = channel[c].pop() +        for i in range(s, t + 1): +            T[i] += 1 +print(max(T))