CodeEff/ECCO huggingface dataset:
# Original solution
N, C = list(map(int, input().split()))
TVs = [[] for i in range(C)]
for i in range(N):
    s, t, c = list(map(int, input().split()))
    TVs[c - 1].append((s, t))

periods = [0] * (2 * 10 ** 5)

for c, TVc in enumerate(TVs):
    ps = [0] * (2 * 10 ** 5)

    for s, t in TVc:
        ps[s * 2 - 1: t * 2 - 2 + 1] = list([x + 1 for x in ps[s * 2 - 1: t * 2 - 2 + 1]])

    for i in range(len(ps) - 1):
        ps[i] = max(ps[i], ps[i + 1])

    periods = list(map(sum, list(zip(periods, ps))))

print((max(periods)))


# Optimized solution
import heapq

N, C = list(map(int, input().split()))
TVs = [[] for i in range(C)]
for i in range(N):
    s, t, ch = list(map(int, input().split()))
    TVs[ch - 1].append((s, t))

pq = []
for ch, TVc in enumerate(TVs):
    if not TVc: continue
    TVc.sort()
    heapq.heappush(pq, (TVc[0][0] - 0.5, ch))

states = [0] * C
iTVs = [0] * C

prev = 0
ans = 0
while pq:
    tm, ch = heapq.heappop(pq)
    if tm != prev:
        ans = max(ans, sum(states))
        prev = tm

    if states[ch] == 0:
        # チャンネルchの番組録画を、時刻tmから開始
        states[ch] = 1
        heapq.heappush(pq, (TVs[ch][iTVs[ch]][1], ch)) # 終了時刻をpqに追加
    else:
        # チャンネルchの番組録画を、時刻tmで終了
        states[ch] = 0
        iTVs[ch] += 1
        if iTVs[ch] >= len(TVs[ch]): continue

        if tm == TVs[ch][iTVs[ch]][0]:
            # 録画範囲が連続しているならば、次の番組録画を開始
            states[ch] = 1
            heapq.heappush(pq, (TVs[ch][iTVs[ch]][1], ch)) # 終了時刻をpqに追加
        else:
            heapq.heappush(pq, (TVs[ch][iTVs[ch]][0] - 0.5, ch)) # 次の開始時刻をpqに追加

print(ans)
# Original solution
from itertools import accumulate
N, C = list(map(int, input().split()))
STC = [list(map(int, input().split())) for _ in range(N)]

M = 10**5+1
merge = [[0]*(M+1) for _ in range(31)]
for i in range(N):
    s, t, c = STC[i]
    merge[c][s] += 1
    merge[c][t+1] -= 1
for c in range(31):
    merge[c] = list([int(bool(x)) for x in accumulate(merge[c])])

ans = []
for i in range(M+1):
    res = 0
    for j in range(31):
        res += merge[j][i]
    ans.append(res)
print((max(ans)))


# Optimized solution
from itertools import accumulate
N, C = list(map(int, input().split()))
STC = [list(map(int, input().split())) for _ in range(N)]

M = 10**5+1
merge = [[0]*(M+1) for _ in range(31)]
for i in range(N):
    s, t, c = STC[i]
    #merge[c][s] += 1
    #merge[c][t+1] -= 1
    merge[c][s:t+1] = [1]*(t-s+1)
#for c in range(31):
#    merge[c] = list(map(lambda x: int(bool(x)), accumulate(merge[c])))
print((max(list(map(sum, list(zip(*merge)))))))

#ans = []
#for i in range(M+1):
#    res = 0
#    for j in range(31):
#        res += merge[j][i]
#    ans.append(res)
#print(max(ans))
# Original solution
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

N,C=rl()
st = [[] for _ in range(C)]
TT1 = [0 for _ in range(10**5+2)]
for i in range(N):
    s,t,c = rl()
    TT1[s] += 1
    TT1[t+1] -= 1
    st[c-1].append([s,t])
for st_i in range(len(st)):
    st_ = st[st_i]
    if len(st_) <= 1: continue
    st_.sort(key=lambda x:x[0])
    l = []
    new = 0
    lst_ = len(st_)
    for i in range(lst_):
        if new == 0:
            s,t = st_[i]
            if i != lst_ -1 and t==st_[i+1][0]:
               new = 1
               continue
            else:
                l.append([s,t])
        else:
            t = st_[i][1]
            if i != lst_ -1 and t==st_[i+1][0]:
                new = 1
                continue
            else:
                l.append([s,t])
    st[st_i] = l


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

for st_ in st:
    if len(st_) == 0: continue
    for i in range(len(st_)):
        TT2[st_[i][0]] += 1
        TT2[st_[i][1]+1] -= 1

for i in range(1,len(TT1)):
    TT1[i] += TT1[i-1]
    TT2[i] += TT2[i-1]

print(min(max(TT1),max(TT2)))


# Optimized solution
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

N,C=rl()
stc = [rl() for _ in range(N)]
stc.sort(key=lambda x:(x[2],x[0]))
nstc = []
for s,t,c in stc:
    if len(nstc) != 0 and nstc[-1][2] == c and nstc[-1][1] == s:
        nstc[-1][1] = t
    else:
        nstc.append([s,t,c])

n = len(nstc)

TT=[0]*(2*10**5+5)
for i in range(n):
    TT[2*nstc[i][0] - 1] += 1
    TT[2*nstc[i][1]] -= 1
for i in range(1,len(TT)):
    TT[i] += TT[i-1]
print(max(TT))
# Original solution
from collections import defaultdict
from itertools import accumulate

n, v = list(map(int, input().split()))
programs = defaultdict(list)
for _ in range(n):
    s, t, c = list(map(int, input().split()))
    programs[c].append((s, t))

imos = [0] * (2 * 10 ** 5 + 2)
for c, p in list(programs.items()):
    p.sort()
    ps, pt = p[0]
    for s, t in p[1:]:
        if pt == s:
            pt = t
        else:
            imos[2 * ps - 1] += 1
            imos[2 * pt + 1] -= 1
            ps, pt = s, t
    imos[2 * ps - 1] += 1
    imos[2 * pt + 1] -= 1

print((max(accumulate(imos))))


# Optimized solution
from collections import defaultdict
from itertools import accumulate

n, v = list(map(int, input().split()))
programs = defaultdict(list)
for _ in range(n):
    s, t, c = list(map(int, input().split()))
    programs[c].append((s, t))

imos = [0] * (10 ** 5 + 2)
for c, p in list(programs.items()):
    p.sort()
    ps, pt = p[0]
    for s, t in p[1:]:
        if pt == s:
            pt = t
        else:
            imos[ps - 1] += 1
            imos[pt] -= 1
            ps, pt = s, t
    imos[ps - 1] += 1
    imos[pt] -= 1

print((max(accumulate(imos))))
# Original solution
N, C = list(map(int, input().split()))

tt = [[0] * (2 * 10 ** 5 + 1) for _ in range(30)]
for _ in range(N):
    s, t, c = list(map(int, input().split()))
    ttc = tt[c - 1]
    for i in range(s * 2 - 1, t * 2):
        ttc[i] = 1

ct = [0] * (2 * 10 ** 5 + 1)
for i in range(30):
    tti = tt[i]
    for j in range(2 * 10 ** 5 + 1):
        ct[j] += tti[j]

print((max(ct)))


# Optimized solution
from operator import itemgetter

N, C = list(map(int, input().split()))
stc = [list(map(int, input().split())) for _ in range(N)]
stc.sort(key=itemgetter(2, 0))

cs = [0] * (10 ** 5 * 2 + 1)
pc = -1
for s, t, c in stc:
    if pc != c:
        pt = -1
        pc = c
    if pt == s:
        cs[s * 2] += 1
    else:
        cs[s * 2 - 1] += 1
    cs[t * 2] -= 1
    pt = t

for i in range(1, 10 ** 5 * 2 + 1):
    cs[i] += cs[i - 1]

print((max(cs)))
# Original solution
N, C = list(map(int, input().split()))

tt = [[0] * (10 ** 5 + 1) for _ in range(30)]
for _ in range(N):
    s, t, c = list(map(int, input().split()))
    ttc = tt[c - 1]
    for i in range(s - 1, t):
        ttc[i] = 1

ct = [0] * (10 ** 5 + 1)
for i in range(30):
    tti = tt[i]
    for j in range(10 ** 5 + 1):
        ct[j] += tti[j]

print((max(ct)))


# Optimized solution
# imos 法
from operator import itemgetter

N, C = list(map(int, input().split()))
stc = [list(map(int, input().split())) for _ in range(N)]
stc.sort(key=itemgetter(2, 0))

cs = [0] * (10 ** 5 + 1)
pc = -1
for s, t, c in stc:
    if pc != c:
        pt = -1
        pc = c
    if pt == s:
        cs[s] += 1
    else:
        cs[s - 1] += 1
    cs[t] -= 1
    pt = t

for i in range(1, 10 ** 5 + 1):
    cs[i] += cs[i - 1]

print((max(cs)))
# Original solution
N, C = list(map(int, input().split()))

tt = [[0] * (10 ** 5 + 1) for _ in range(C)]
for _ in range(N):
    s, t, c = list(map(int, input().split()))
    for i in range(s - 1, t):
        tt[c - 1][i] = 1

ct = [0] * (10 ** 5 + 1)
for i in range(C):
    for j in range(10 ** 5 + 1):
        ct[j] += tt[i][j]

print((max(ct)))


# Optimized solution
# imos 法
from operator import itemgetter

N, C = list(map(int, input().split()))
stc = [list(map(int, input().split())) for _ in range(N)]
stc.sort(key=itemgetter(2, 0))

cs = [0] * (10 ** 5 + 1)
pt, pc = -1, -1
for s, t, c in stc:
    if pt == s and pc == c:
        cs[s] += 1
    else:
        cs[s - 1] += 1
    cs[t] -= 1
    pt, pc = t, c

for i in range(1, 10 ** 5 + 1):
    cs[i] += cs[i - 1]

print((max(cs)))
# Original solution
N, C = list(map(int, input().split()))
prog = []
for _ in range(N):
    prog.append(list(map(int, input().split())))

ans = 0
T = 10**5
print((max([len(list([x for x in prog if x[0] <= i <= x[1]]))
           for i in range(T+1)])))


# Optimized solution
from itertools import accumulate
# -*- coding: utf-8 -*-
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, C = list(map(int, input().split()))
TV = dict()
programs = [list(map(int, input().split())) for _ in range(N)]
last_time = max([p[1] for p in programs])
for i in range(1, C+1):
    TV[i] = [0]*(last_time*2+2)

for s, t, c in programs:
    s *= 2
    t *= 2
    TV[c][s] += 1
    TV[c][t+1] -= 1

for c in range(1, C+1):
    TV[c] = list(accumulate(TV[c]))

ans = 0
for i in range(last_time*2+1):
    tmp = 0
    for c in range(1, C+1):
        if TV[c][i] > 0:
            tmp += 1
    ans = max(ans, tmp)
print(ans)
# Original solution
N, C = list(map(int, input().split()))

channels = [[] for _ in range(C)]
maxT = 0

for _ in range(N) :
    s, t, c = list(map(int, input().split()))
    maxT = max(maxT, t)
    channels[c - 1].append((s, t))

maxT = maxT * 2 + 10
tvSum = [0 for _ in range(maxT)]

for tv in channels :
    imos = [0 for _ in range(maxT)]
    for (s, t) in tv :
        imos[s * 2 - 1] += 1
        imos[t * 2] -= 1
    for i in range(1, maxT) :
        imos[i] += imos[i - 1]
    for i in range(maxT) :
        if imos[i] > 0 :
            tvSum[i] += 1

ans = 0
for i in range(maxT) :
    ans = max(ans, tvSum[i])

print(ans)


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

channels = [[] for _ in range(C)]
maxT = 0

for _ in range(N) :
    s, t, c = list(map(int, input().split()))
    maxT = max(maxT, t)
    channels[c - 1].append((s, t))

maxT = maxT * 2 + 10
tvSum = [0 for _ in range(maxT)]

for tv in channels :
    imos = [0 for _ in range(maxT)]
    for (s, t) in tv :
        imos[s * 2 - 1] += 1
        imos[t * 2] -= 1
    for i in range(1, maxT) :
        imos[i] += imos[i - 1]
    for i in range(maxT) :
        if imos[i] > 0 :
            tvSum[i] += 1

print((max(tvSum)))
# Original solution
import sys

def main():
    input = sys.stdin.readline
    N, C = list(map(int, input().split()))
    dic = [[] for _ in range(C + 1)]
    for _ in range(N):
        s, t, c = input().split()
        dic[int(c)].append([int(s), int(t)])
    for c in range(C + 1):
        l = len(dic[c])
        if l == 1:
            continue
        dic[c] = sorted(dic[c])
        i = 0
        while i < l - 1:
            if i < l - 1 and dic[c][i][1] == dic[c][i + 1][0]:
                dic[c][i + 1][0] = dic[c][i][0]
                dic[c].pop(i)
                l -= 1
            else:
                i += 1
    f = [0 for _ in range(100002)]
    for c in range(C + 1):
        for t in dic[c]:
            f[t[0]] += 1
            f[t[1] + 1] -= 1

    ans = 0
    for i in range(1, 100001):
        f[i] += f[i - 1]
        if ans < f[i]:
            ans = f[i]
    print(ans)

if __name__ == "__main__":
    main()

# Optimized solution
import sys

def main():
    input = sys.stdin.readline
    N, C = list(map(int, input().split()))
    dic = [[] for _ in range(C + 1)]
    for _ in range(N):
        s, t, c = input().split()
        dic[int(c)].append([int(s), int(t)])
    for c in range(C + 1):
        l = len(dic[c])
        if l == 1:
            continue
        dic[c] = sorted(dic[c])
        i = 0
        while i < l - 1:
            if i < l - 1 and dic[c][i][1] == dic[c][i + 1][0]:
                dic[c][i + 1][0] += 1
            else:
                i += 1
    f = [0 for _ in range(100002)]
    for c in range(C + 1):
        for t in dic[c]:
            f[t[0]] += 1
            f[t[1] + 1] -= 1
    ans = 0
    for i in range(1, 100001):
        f[i] += f[i - 1]
        if ans < f[i]:
            ans = f[i]
    print(ans)

if __name__ == "__main__":
    main()
# Original solution
n,c = list(map(int,input().split()))
program = [list(map(int,input().split())) for i in range(n)]
time = [0 for i in range(10**5+1)]

program.sort()
program.sort(key = lambda x: x[2])
 
for i in range(1,n):
    if program[i][2]==program[i-1][2] and program[i][0]==program[i-1][1]:
        program[i][0] = program[i-1][0]
        program[i-1][0] = None
#print(program)
 
for i in range(n):
    if program[i][0] == None:
        continue
    time[program[i][0]-1] += 1
    time[program[i][1]] -= 1
 
count = 0
max_count = 0
 
for i in range(10**5+1):
    count += time[i]
    max_count = max(max_count,count)
 
print(max_count)

# Optimized solution
n,c = list(map(int,input().split()))
ab = []
for _ in range(n):
    s, t, cha = (int(x) for x in input().split())
    ab.append([s, t, cha])

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

for i in range(1,n):
    if ab[i][0] == ab[i-1][1] and ab[i][2] == ab[i-1][2]:
        ab[i][0] = ab[i-1][0]
        ab[i-1][0] = -1

time = [0]*(10**5+1)

for i in range(n):
    if ab[i][0] == -1:
        continue
    time[ab[i][0]-1] += 1
    time[ab[i][1]] -= 1

ans = 0
memo = 0

for i in time:
    memo += i
    ans = max(ans,memo)

print(ans)
# Original solution
import functools
N, C = list(map(int, input().split()))
T = [[0 for i in range(10 ** 5 + 1)] for j in range(C)]
for i in range(N):
  s, t, c = list(map(int, input().split()))
  for j in range(s - 1, t):
    T[c - 1][j] = 1
ans = 0
for j in range(10 ** 5 + 1):
  r = 0
  for i in range(C):
    r += T[i][j]
  ans = max(ans, r)
print(ans)

# Optimized solution
import functools
N, C = list(map(int, input().split()))
P = [[0 for c in range(C)] for i in range(10 ** 5 + 1)]
T = 0
for i in range(N):
  s, t, c = list(map(int, input().split()))
  T = max(t, T)
  for j in range(s - 1, t):
    P[j][c - 1] = 1
ans = 0
for p in P[:T + 1]:
  ans = max(sum(p), ans)
print(ans)
# Original solution
N, C = list(map(int, input().split()))
stc = [[int(x) for x in input().split()] for _ in range(N)]

im = [[0] * (10**5 + 1) for _ in range(C + 1)]
for x in stc:
    s,t,c = x
    im[c][s] += 1
    im[c][t] -= 1

for c in range(1, C + 1):
    v = 0
    for i in range(1, 10**5 + 1):
        n = im[c][i]
        v += n
        if n > 0:
            im[c][i - 1] += 1
        im[c][i] = v
print((max([sum(x) for x in zip(*im[1:])])))

# Optimized solution
import operator
N, C = list(map(int, input().split()))
stc = [[int(x) for x in input().split()] for _ in range(N)]

united = []
pc,ps,pt = 0,0,0
for x in sorted(stc, key=operator.itemgetter(2,0,1)):
    s, t, c = x
    if c == pc and s == pt:
        united[-1][1] = t
    else:
        united.append([s, t, c])
    ps, pt, pc = x
cnt = [0] * (10**5 + 1)
for x in united:
    s,t,c = x
    for i in range(s - 1, t):
        cnt[i] += 1
print((max(cnt)))
# Original solution
N, C = list(map(int, input().split()))
channel_list = [[0 for _ in range(10**5+1)]for _ in range(C)]
count_list = [0 for _ in range(10**5+1)]
for i in range(N):
    s, t, c = list(map(int, input().split()))
    channel_list[c-1][s-1] += 1
    channel_list[c-1][t] -= 1

for i in range(C):
    for t in range(1, 10**5):
        if t == 10 ** 5:
            continue
        channel_list[i][t] += channel_list[i][t-1]
        if channel_list[i][t] >= 1:
            count_list[t] += 1
x = 0
for t in range(1, 10**5+1):
    count = count_list[t]
    if count > x:
        x = count
print(x)


# Optimized solution
N, C = list(map(int, input().split()))
channel_list = [[0 for _ in range(10**5+1)]for _ in range(C)]
count_list = [0 for _ in range(10**5+1)]
for i in range(N):
    s, t, c = list(map(int, input().split()))
    channel_list[c-1][s-1] += 1
    channel_list[c-1][t] -= 1

for i in range(C):
    for t in range(1, 10**5+1):
        channel_list[i][t] += channel_list[i][t-1]
        if channel_list[i][t] >= 1:
            count_list[t] += 1

print((max(count_list)))
# Original solution
N, C = list(map(int, input().split()))
channel_list = [[0 for _ in range(10**5+1)]for _ in range(C)]
count_list = [0 for _ in range(10**5+1)]
for i in range(N):
    s, t, c = list(map(int, input().split()))
    channel_list[c-1][s-1] += 1
    channel_list[c-1][t] -= 1

for i in range(C):
    for t in range(1, 10**5+1):
        channel_list[i][t] += channel_list[i][t-1]
        if channel_list[i][t] >= 1:
            count_list[t] += 1

print((max(count_list)))


# Optimized solution
N, C = list(map(int, input().split()))
time = 10**5+1
channel_list = [[0 for _ in range(time)]for _ in range(C)]
count_list = [0 for _ in range(time)]
for i in range(N):
    s, t, c = list(map(int, input().split()))
    channel_list[c-1][s-1] += 1
    channel_list[c-1][t] -= 1

for i in range(C):
    for t in range(1, time):
        channel_list[i][t] += channel_list[i][t-1]
        if channel_list[i][t] >= 1:
            count_list[t] += 1

print((max(count_list)))
# Original solution
# N個のimosなので二次元でやる 0.5がうざいので*2する( (2*10^5) * C )

# なぜか2WAが取れない

# 嘘解法？

N, C = list(map(int, input().split()))
x = 2 * (10**5)
# x = 30  # test
imos = [[0 for _ in range(x)] for _ in range(C)]
for _ in range(N):
    s, t, c = list(map(int, input().split()))
    s, t, c = s * 2 - 1, t * 2 - 1, c - 1
    imos[c][s - 1] += 1
    imos[c][t] -= 1

for i in range(C):
    for j in range(1, x):
        imos[i][j] += imos[i][j - 1]
        imos[i][j] = min(1, imos[i][j])  # test

ans = 0
for j in range(x):
    tmp = 0
    for i in range(C):
        tmp += imos[i][j]
    ans = max(ans, tmp)
# print("-----------")
# for x in imos:
#     print(x)
print(ans)

# 1 3
# 3 4 2


# Optimized solution
# N個のimosなので二次元でやる 0.5がうざいので*2する( (2*10^5) * C )

# なぜか2WAが取れない

# これ嘘解法ぽい気がする

N, C = list(map(int, input().split()))
x = 2 * (10**5)
# x = 30  # test
imos = [[0 for _ in range(x)] for _ in range(C)]
for _ in range(N):
    s, t, c = list(map(int, input().split()))
    s, t, c = s * 2 - 1, t * 2 - 1, c - 1
    imos[c][s - 1] += 1
    imos[c][t] -= 1
    # imos[c][s - 1] = min(1, imos[c][s - 1])  # test

for i in range(C):
    for j in range(1, x):
        imos[i][j] += imos[i][j - 1]
        # imos[i][j] = min(1, imos[i][j])  # test

ans = 0
for j in range(x):
    tmp = 0
    for i in range(C):
        tmp += min(1, imos[i][j])
    ans = max(ans, tmp)
# print("-----------")
# for x in imos:
#     print(x)
print(ans)

# 1 3
# 3 4 2
# Original solution
N,C = list(map(int, input().split()))
L = [[int(a) for a in input().split()] for _ in range(N)]

ans = [[0, 0] for _ in range(C)]
L.sort()
for i in range(N):
    j = 0
    while j < C:
        if ans[j][0] == L[i][0] and ans[j][1] == L[i][2]:
            ans[j][0] = L[i][1]
            j = C
        elif ans[j][0] < L[i][0]:
            ans[j][0] = L[i][1]
            ans[j][1] = L[i][2]
            j = C
        j += 1
    ans.sort(reverse=True)
    
num = 0
for i in range(C):
    if ans[i][0] > 0:
        num += 1
        
print(num)

# Optimized solution
N,C = list(map(int, input().split()))
L = [[int(a) for a in input().split()] for _ in range(N)]

ans = [0]*C
chan = [0]*C
L.sort()
for i in range(N):
    for j in range(C):
        if ans[j] == L[i][0] and chan[j] == L[i][2]:
            ans[j] = L[i][1]
            break
        elif ans[j] < L[i][0]:
            ans[j] = L[i][1]
            chan[j] = L[i][2]
            break
    ans.sort(reverse=True)
    
num = 0
for i in range(C):
    if ans[i] > 0:
        num += 1
        
print(num)
# Original solution
# heapqの方針で上手くいかなかった
# 解説放送を見てimosにした

def main():
    from collections import namedtuple
    from heapq import heappop, heappush
    import sys
    input = sys.stdin.readline

    Prog = namedtuple('Prog', 'L R')
    Prog.__eq__ = lambda self, other: self.R == other.R
    Prog.__lt__ = lambda self, other: self.R < other.R

    N, C = list(map(int, input().split()))
    ps = [[] for _ in range(30)]
    for _ in range(N):
        l, r, ch = list(map(int, input().split()))
        heappush(ps[ch - 1], Prog(l, r))

    imos = [0] * (10 ** 5 + 1)
    for ps_ch in ps:
        while ps_ch:
            l, r = heappop(ps_ch)
            while ps_ch and ps_ch[0].L == r:
                r = ps_ch[0].R
                heappop(ps_ch)
            else:
                imos[l - 1] += 1
                imos[r] -= 1

    ans = imos[0]
    for i in range(10 ** 5):
        imos[i + 1] += imos[i]
        ans = max(ans, imos[i + 1])

    print(ans)


if __name__ == '__main__':
    main()


# Optimized solution
# heapqの方針で上手くいかなかった
# 解説放送を見てimosにした

def main():
    from collections import namedtuple
    from heapq import heappop, heappush
    import sys
    input = sys.stdin.readline

    Prog = namedtuple('Prog', 'L R')
    Prog.__eq__ = lambda self, other: self.R == other.R
    Prog.__lt__ = lambda self, other: self.R < other.R

    N, C = list(map(int, input().split()))
    ps = tuple([] for _ in range(30))
    for _ in range(N):
        l, r, ch = list(map(int, input().split()))
        heappush(ps[ch - 1], Prog(l, r))

    imos = [0] * (10 ** 5 + 1)
    for ps_ch in ps:
        while ps_ch:
            l, r = heappop(ps_ch)
            while ps_ch and ps_ch[0].L == r:
                r = ps_ch[0].R
                heappop(ps_ch)
            else:
                imos[l - 1] += 1
                imos[r] -= 1

    for i in range(10 ** 5):
        imos[i + 1] += imos[i]

    print((max(imos)))


if __name__ == '__main__':
    main()
# Original solution
import copy

N,C=list(map(int,input().split()))
channel=[tuple(map(int,input().split())) for i in range(N)]
channel=sorted(channel,key=lambda cha: cha[0])

n=0
while(channel!=[]):
    c=copy.copy(channel)
    n+=1
    pro=channel[0]
    c.remove(pro)
    for i in channel:
        if i[0]>pro[1]:
            pro=i
            c.remove(pro)
    channel=c
print(n)


# Optimized solution
N,C=list(map(int,input().split()))
channel=[tuple(map(int,input().split())) for i in range(N)]
channel=sorted(channel,key=lambda cha: cha[0])

n=0
while(channel!=[]):
    c=[]
    n+=1
    pro=channel[0]
    channel.remove(pro)
    for i in channel:
        if i[0]>pro[1]:
            pro=i
        elif(i[0]==pro[1] and i[2]==pro[2]):
            pro=i
        else:
            c.append(i)
    channel=c
print(n)