import sys

import math

from itertools import accumulate as acc



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





a=[[0 for i in range(10**5+1)] for i in range(C+1)]



rec=[0 for i in range(10**5+1)]



for i in range(N):

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

    recs,rect=a[c][s],a[c][t]

    if recs==0 and rect==0:

        rec[s-1]+=1

        rec[t]-=1

    elif recs==0 and rect==1:

        rec[s-1]+=1

        rec[t-1]-=1

    elif recs==1 and rect==0:

        rec[s]+=1

        rec[t]-=1

    elif recs==1 and rect==1:

        rec[s]+=1

        rec[t-1]-=1



    a[c][s],a[c][t]=1,1



tmp=0

ans=0

for i in range(10**5):

    tmp+=rec[i]

    ans=max(tmp,ans)

print(ans)
import sys

import math

from itertools import accumulate as acc



input=sys.stdin.readline



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





a=[[0 for i in range(10**5+1)] for i in range(C+1)]



rec=[0 for i in range(10**5+1)]



for i in range(N):

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

    recs,rect=a[c][s],a[c][t]

    if recs==0 and rect==0:

        rec[s-1]+=1

        rec[t]-=1

    elif recs==0 and rect==1:

        rec[s-1]+=1

        rec[t-1]-=1

    elif recs==1 and rect==0:

        rec[s]+=1

        rec[t]-=1

    elif recs==1 and rect==1:

        rec[s]+=1

        rec[t-1]-=1



    a[c][s],a[c][t]=1,1



tmp=0

ans=0

for i in range(10**5):

    tmp+=rec[i]

    ans=max(tmp,ans)

print(ans)
import sys
import math
from itertools import accumulate as acc

N, C = list(map(int, input().split()))
a = [[0 for i in range(10**5 + 1)] for i in range(C + 1)]
rec = [0 for i in range(10**5 + 1)]
for i in range(N):
    s, t, c = list(map(int, input().split()))
    recs, rect = a[c][s], a[c][t]
    if recs == 0 and rect == 0:
        rec[s - 1] += 1
        rec[t] -= 1
    elif recs == 0 and rect == 1:
        rec[s - 1] += 1
        rec[t - 1] -= 1
    elif recs == 1 and rect == 0:
        rec[s] += 1
        rec[t] -= 1
    elif recs == 1 and rect == 1:
        rec[s] += 1
        rec[t - 1] -= 1
    a[c][s], a[c][t] = 1, 1
tmp = 0
ans = 0
for i in range(10**5):
    tmp += rec[i]
    ans = max(tmp, ans)
print(ans)

import sys
import math
from itertools import accumulate as acc

input = sys.stdin.readline
N, C = list(map(int, input().split()))
a = [[0 for i in range(10**5 + 1)] for i in range(C + 1)]
rec = [0 for i in range(10**5 + 1)]
for i in range(N):
    s, t, c = list(map(int, input().split()))
    recs, rect = a[c][s], a[c][t]
    if recs == 0 and rect == 0:
        rec[s - 1] += 1
        rec[t] -= 1
    elif recs == 0 and rect == 1:
        rec[s - 1] += 1
        rec[t - 1] -= 1
    elif recs == 1 and rect == 0:
        rec[s] += 1
        rec[t] -= 1
    elif recs == 1 and rect == 1:
        rec[s] += 1
        rec[t - 1] -= 1
    a[c][s], a[c][t] = 1, 1
tmp = 0
ans = 0
for i in range(10**5):
    tmp += rec[i]
    ans = max(tmp, ans)
print(ans)

+input = sys.stdin.readline