Joisino is planning to record N TV programs with recorders.
The TV can receive C channels numbered 1 through C.
The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i.
Here, there will never be more than one program that are broadcast on the same channel at the same time.
When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T).
Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.

-----Constraints-----
 - 1≤N≤10^5
 - 1≤C≤30
 - 1≤s_i<t_i≤10^5
 - 1≤c_i≤C
 - If c_i=c_j and i≠j, either t_i≤s_j or s_i≥t_j.
 - All input values are integers.

-----Input-----
Input is given from Standard Input in the following format:
N C
s_1 t_1 c_1
:
s_N t_N c_N

-----Output-----
When the minimum required number of recorders is x, print the value of x.

-----Sample Input-----
3 2
1 7 2
7 8 1
8 12 1

-----Sample Output-----
2

Two recorders can record all the programs, for example, as follows:
 - With the first recorder, record Channel 2 from time 1 to time 7. The first program will be recorded. Note that this recorder will be unable to record other channels from time 0.5 to time 7.
 - With the second recorder, record Channel 1 from time 7 to time 12. The second and third programs will be recorded. Note that this recorder will be unable to record other channels from time 6.5 to time 12.

Difficulty: interview

Starter code:

Solutions:
n, C = map(int, input().split())
time = 0
stc = []
for i in range(n):
    temp = list(map(int, input().split()))
    time = max(time, temp[1])
    stc.append(temp)
tv = [[0 for i in range(C)] for i in range(time + 1)]
for i in stc:
    s, t, c = i[0], i[1], i[2]
    for j in range(s, t + 1):
        tv[j][c - 1] = 1
ans = 0
for i in tv:
    ans = max(ans, sum(i))
print(ans)

n, c = list(map(int, input().split()))
# input時に前処理として以下のことをしておく
#   * 開始時間を-1(-0.5の制約だが、-1しても変わらないので-1する)しておく

# テレビ局の番組をチャンネルごとに登録
r = [[0 for i in range(c)] for j in range(100000)]
for _ in range(n):
    s,t,c = list(map(int, input().split()))
    for j in range(s-1, t):
        r[j][c - 1] = 1
# print(*r,sep='\n')

ans = 0
for i in range(len(r)):
    ans = max(ans, sum(r[i]))
print(ans)


# 補足
# チャンネル数4の場合以下のような配列ができる
# 1行でとある時間のチャンネル状態(1: 録画する, 0: 録画しない)がつく
#[0, 0, 0, 0]
#[0, 0, 1, 0]
#[1, 1, 1, 0]  <- この時間で3チャンネル録画が必要
#[1, 1, 0, 0]  <- この時間で2チャンネル録画が必要
#[1, 1, 0, 0]
#[1, 0, 0, 0]


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

ans = C
d = [list() for _ in range(C+1)]
for _ in range(N):
    s, t, c = list(map(int, input().split()))
    d[c].append([s, t])

S = [0]*(10**5+1)
T = [0]*(10**5+1)

for i in range(C+1):
    if not d[i]:
        continue
    d[i].sort()
    s, t = d[i][0]
    for j in range(1, len(d[i])):
        if t == d[i][j][0]:
            t = d[i][j][1]
        else:
            S[s] += 1
            T[t] += 1
            s, t = d[i][j]
    S[s] += 1
    T[t] += 1

temp = 0
ans = 0
for i in range(1, 10**5+1):
    temp += S[i]-T[i-1]
    ans = max(ans, temp)
    
print(ans)


def main():
    from itertools import accumulate
    n, c, *stc = list(map(int, open(0).read().split()))
    table = [0] * 2 * (10 ** 5 + 1)
    m = list(zip(stc[::3], stc[1::3], stc[2::3]))
    m.sort(key=lambda a: (a[2], a[0], a[1]))

    ch_ = 0
    t_ = 0
    for s, t, ch in m:
        if ch != ch_:
            ch_ = ch
            t_ = 0
        if t_ == 2 * s:
            table[t_ + 1] += 1
        else:
            table[2 * s - 1] += 1

        table[2 * t + 1] -= 1
        t_ = 2 * t

    *x, = accumulate(table)
    ans = max(x)

    print(ans)


def __starting_point():
    main()

__starting_point()

import sys
from collections import *
import heapq
import math
# from math import gcd
import bisect
import copy
from itertools import permutations,accumulate,combinations,product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,c=map(int,input().split())
stc=[list(map(int,input().split())) for i in range(n)]
stc.sort()
lst=[0]*c
for i in range(n):
    s,t,ctmp=stc[i]
    for j in range(c):
        if lst[j]==0:
            lst[j]=stc[i]
            break
        else:
            if lst[j][2]==ctmp:
                lst[j]=stc[i]
                break
            elif lst[j][1]<s:
                lst[j]=stc[i]
                break
# print(lst)
ans=0
for i in range(c):
    if lst[i]!=0:
        ans+=1
print(ans)

n,c=list(map(int,input().split()))
table=[0]*220000
chanels=[[]for i in range(c)]
for i in range(n):
    a,s,ch=list(map(int,input().split()))
    chanels[ch-1].append((a,s))
for i in range(c):
    if chanels[i]:
        chanels[i].sort()
        x,y=chanels[i][0]
        for p,q in chanels[i][1:]+[(0,0)]:
            if y==p:y=q
            else:
                table[2*x-1]+=1
                table[2*y]-=1
                x,y=p,q

from itertools import accumulate
print((max(list(accumulate(table)))))


class Imos:
    def __init__(self, n):
        self.B = [0] * n
        self.n = n
        from itertools import accumulate
        self.ac = accumulate

    def __call__(self, l, r):
        l, r = max(l, 0), min(r, self.n - 1)
        self.B[l] += 1
        if r + 1 != self.n:
            self.B[r + 1] -= 1

    def out(self):
        *res, = self.ac(self.B)
        return res

from collections import defaultdict
d = defaultdict(list)
imos = Imos(10 ** 5 + 1)

(N, C), *D = [[*map(int, o.split())] for o in open(0)]
for s, t, c in D:
    d[c] += (s, t),
for p in d.values():
    p.sort()
    ps, pt = p[0]
    for s, t in p[1:] + [[0,0]]:
        if pt == s:
            pt = t
        else:
            imos(ps - 1, pt - 1)
            ps, pt = s, t
print(max(imos.out()))

def main():
    from itertools import accumulate
    n, c, *stc = list(map(int, open(0).read().split()))
    table = [0] * (10 ** 5 + 2)
    m = list(zip(stc[::3], stc[1::3], stc[2::3]))
    m.sort(key=lambda a: (a[2], a[0], a[1]))

    ch_ = 0
    t_ = 0
    for s, t, ch in m:
        if ch != ch_:
            ch_ = ch
            t_ = 0
        if t_ == s:
            table[t_ + 1] += 1
        else:
            table[s] += 1

        table[t + 1] -= 1
        t_ = t

    *x, = accumulate(table)
    ans = max(x)

    print(ans)


def __starting_point():
    main()

__starting_point()

n, c = map(int, input().split())
cnt = [[0 for _ in range(10 ** 5 + 1)] for _ in range(c)]

for _ in range(n):
    s, t, _c = map(int, input().split())
    for j in range(s, t + 1):
        cnt[_c - 1][j] = 1
ans = 0
for i in range(10 ** 5 + 1):
    ans = max(ans, sum(cnt[j][i] for j in range(c)))
print(ans)

def main():
    from itertools import accumulate
    n, c, *stc = list(map(int, open(0).read().split()))
    table = [0] * (10 ** 5 + 2)
    m = sorted(list(zip(*[iter(stc)] * 3)), key=lambda a: (a[2], a[0]))

    ch_ = 0
    t_ = 0
    for s, t, ch in m:
        if ch != ch_:
            ch_ = ch
            t_ = 0
        if t_ == s:
            table[t_ + 1] += 1
        else:
            table[s] += 1

        table[t + 1] -= 1
        t_ = t

    *x, = accumulate(table)
    ans = max(x)

    print(ans)


def __starting_point():
    main()

__starting_point()

N, C = map(int, input().split())
sch = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[0])
rec = [[0, 0] for _ in range(C+1)]
num_rec = 1

for i in range(N):
    s, t, c = sch[i]
    start = False
    for j in range(1, num_rec + 1):
        if rec[j][0] - int(rec[j][1] == c) < s:
            rec[j] = [t, c]
            start = True
            break
    if not start:
        num_rec += 1
        rec[num_rec] = [t, c]
    
print(num_rec)

def main():
    N, C = list(map(int, input().split()))
    l = []
    for _ in range(N):
        s, t, c = list(map(int, input().split()))
        l.append((s,t,c))
    l.sort(key=lambda x: x[0])
    r = []
    for i in l:
        if not r:
            r.append((i[1], i[2]))
            continue
        for j, v in enumerate(r):
            if v[0] < i[0] or (v[1] == i[2] and v[0] == i[0]):
                r[j] = (i[1], i[2])
                break
        else:
            r.append((i[1], i[2]))
        r.sort(key=lambda x:x[0])
    print((len(r)))
main()


N,C=map(int, input().split())
A=[list(map(int, input().split())) for _ in range(N)]
D=[[] for i in range(C)]
DD=[[] for i in range(C)]
for s,t,c in A:
  D[c-1].append([s,t])
for i in range(C):
  E=sorted(D[i])
  e=len(E)
  for j in range(e):
    if j==0:
      DD[i].append([E[j][0],E[j][1]])
    elif j!=0 and E[j][0]==E[j-1][1]:
      DD[i][-1][-1]=E[j][1]
    else:
      DD[i].append([E[j][0],E[j][1]])
ANS=[0]*(10**5+3)
for i in range(C):
  F=DD[i]
  for i,j in F:
    ANS[i]+=1
    ANS[j+1]-=1
ans=0
d=0
for i in ANS:
  d+=i
  ans=max(d,ans)
print(ans)

n,c=map(int,input().split())
imos=[[0 for i in range(c)] for j in range(10**5+1)]#1~10**5+1
for i in range(n):
    s,t,_c=map(int,input().split())
    imos[s-1][_c-1]+=1
    imos[t][_c-1]-=1
for i in range(1,10**5+1):
    for j in range(c):
        imos[i][j]+=imos[i-1][j]
imosans=[0]*(10**5+1)
for i in range(10**5+1):
    for j in range(c):
        imosans[i]+=(imos[i][j]>=1)
print(max(imosans))

def main():
    from itertools import accumulate
    n, c, *stc = list(map(int, open(0).read().split()))
    table = [0] * (10 ** 5 + 2)
    m = sorted(list(zip(*[iter(stc)] * 3)), key=lambda a: (a[2], a[0], a[1]))

    ch_ = 0
    t_ = 0
    for s, t, ch in m:
        if ch != ch_:
            ch_ = ch
            t_ = 0
        if t_ == s:
            table[t_ + 1] += 1
        else:
            table[s] += 1

        table[t + 1] -= 1
        t_ = t

    *x, = accumulate(table)
    ans = max(x)

    print(ans)


def __starting_point():
    main()

__starting_point()

from collections import defaultdict
from itertools import accumulate


N, K = map(int, input().split())

timetables = defaultdict(list)
for i in range(N):
    s, t, c = map(int, input().split())
    timetables[c].append([s, t])

for name, times in timetables.items():
    times.sort()
    new = []
    for i, time in enumerate(times):
        s, t = time
        if i == 0:
            new.append([s, t])
            continue
        if s == new[-1][1]:
            new[-1][1] = t
        else:
            new.append([s, t])
    timetables[name] = new

time_count = [0] * 100010
for name, times in timetables.items():
    for s, t in times:
        time_count[s] += 1
        time_count[t + 1] -= 1

acc = accumulate(time_count)

print(max(acc))

n,c = list(map(int,input().split()))

t = [[0 for i in range(100001)] for j in range(c)]

for i in range(n):
    si,ti,ci = list(map(int,input().split()))
    for j in range(si,ti+1):
        t[ci-1][j] = 1
print((max(sum(t[j][i] for j in range(c)) for i in range(100001))))


import math
import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,c = list(map(int,ipt().split()))
    cc = [[] for _ in [0]*c]
    tma = 0
    for i in range(n):
        s,t,c = list(map(int,ipt().split()))
        hpq.heappush(cc[c-1],(s,t))
        if t > tma:
            tma = t
    cnt = np.zeros(tma+1,dtype=int)
    for i in cc:
        ps = -1
        pt = -1
        while len(i) > 0:
            ns,nt = hpq.heappop(i)
            if pt == ns:
                pt = nt
                continue
            elif not pt == -1:
                cnt[ps:pt+1:] += np.ones(pt-ps+1,dtype=int)
            ps = ns
            pt = nt
        if not pt == -1:
            cnt[ps:pt+1:] += np.ones(pt-ps+1,dtype=int)
    print((max(cnt)))
    return

def __starting_point():
    main()

__starting_point()

imos = [0]*(10**5+2)#0~10**5+1

N,C = map(int,input().split())
C = 30
mitai = [[] for i in range(C+1)]

for i in range(N):
    s,t,c = map(int,input().split())
    mitai[c].append([s,t])

for i in range(C+1):
    mitai[i].sort()


for i in range(C+1):
    preT = -1
    for j in mitai[i]:
        s,t = j[0],j[1]
        if preT == s:
            imos[s+1]+=1
            imos[t+1]-=1
        else:
            imos[s]+=1
            imos[t+1]-=1
        preT = t

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

print(max(imos))

import sys
from itertools import accumulate

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, C, *STC = list(map(int, read().split()))

    P = [[] for _ in range(C)]
    for s, t, c in zip(*[iter(STC)] * 3):
        P[c - 1].append((s, t))

    M = 10 ** 5
    vec = [0] * (M + 2)
    for i in range(C):
        P[i].sort()
        for j, (s, t) in enumerate(P[i]):
            if j > 0 and s == P[i][j - 1][1]:
                vec[s] += 1
                vec[t] += -1
            else:
                vec[s - 1] += 1
                vec[t] += -1

    vec = list(accumulate(vec))

    print((max(vec)))
    return


def __starting_point():
    main()

__starting_point()

def main():
    N, C = list(map(int, input().split(' ')))
    progams = [list(map(int, input().split(' '))) for _ in range(N)]
    progams.sort(key=lambda p: p[0])  # sort in ascending order of start time
    recorders = [[0, 0] for _ in range(C)]  # (end time, channel)
    for prog in progams:
        s, t, c = prog
        for i in range(C):
            can_record = (c == recorders[i][1] and recorders[i][0] <= s) or \
                (c != recorders[i][1] and recorders[i][0] < s)
            if can_record:
                recorders[i][0] = t
                recorders[i][1] = c
                break
    ans = 0
    for i in range(C):
        if recorders[i][0] > 0:
            ans += 1
    print(ans)


def __starting_point():
    main()
__starting_point()

from collections import defaultdict
n,c=list(map(int,input().split()))
s=[list(map(int,input().split())) for _ in range(n)]

dd=defaultdict(lambda: [0]*(10**5+1))
for s,t,ch in s:
  for i in range(s,t+1):
    dd[ch][i]=1
ans=0
for i in range(10**5+1):
  cnt=0
  for ch in range(c+1):
    if dd[ch][i]==1:
      cnt+=1
  ans=max(ans,cnt)
print(ans)
  


N,C = 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 = map(int,input().split())
    T[c-1][s] += 1
    T[c-1][t] -= 1
for i in range(C):
    for j in range(10**5):
        T[i][j+1] += T[i][j]

ans = 0
for i in range(1,10**5+1):
    a = 0
    for j in range(C):
        if T[j][i] or T[j][i-1]:
            a += 1
    ans = max(ans,a)
print(ans)

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

print(max([sum(rec[i]) for i in range(10**5)]))

def Csum(a):
    b,c=[0],0
    for i in range(len(a)):
        c+=a[i]
        b.append(c)
    return b

n,c=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
b=[[0]*(10**5+10) for i in range(c)]
for i in a:
    b[i[2]-1][i[0]-1]+=1
    b[i[2]-1][i[1]]-=1
b=[Csum(i) for i in b]
ans=[]
for i in range(10**5+10):
    d=0
    for j in range(c):
        if b[j][i]>0:
            d+=1
    ans.append(d)
print(max(ans))

import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list([int(x) - 1 for x in sys.stdin.readline().rstrip().split()])


# ===CODE===

def main():
    n, c = ns()
    l = 10 ** 5
    table = [[0 for _ in range(l + 1)] for __ in range(c)]

    for _ in range(n):
        s, t, ci = ns()
        ci -= 1
        table[ci][s] += 1
        table[ci][t] -= 1

    ans = 0
    tmp = 0
    for i in range(l + 1):
        fin = 0
        for j in range(c):
            if table[j][i] > 0:
                tmp += table[j][i]
            else:
                fin += table[j][i]
        ans = max(ans, tmp)
        tmp += fin
    print(ans)


def __starting_point():
    main()

__starting_point()

#!/usr/bin python3
# -*- coding: utf-8 -*-

from collections import deque

N, C = list(map(int,input().split()))
Mx = 10**5+1
sch = [[0]*Mx for _ in range(C)]
scht = [0]*Mx
plist = [[] for _ in range(C)]
for _ in range(N):
    s, t, c = list(map(int,input().split()))
    plist[c-1].append((s,t))
for c, p in enumerate(plist):
    p.sort()
    prevt = 0
    for s, t in p:
        if prevt == s:
            sch[c][prevt] = 0
        else:
            sch[c][s] = 1
        sch[c][t] = -1
        prevt = t
    for i in range(1, Mx):
        if sch[c][i]==1:
            scht[i-1]+=1
        if sch[c][i]==-1:
            scht[i]-=1

for i in range(1, Mx):
    scht[i] += scht[i-1]

print((max(scht)))


n, C = map(int, input().split())
stc = [list(map(int, input().split())) for i in range(n)]
m = 0
for i in stc:
    m = max(m, i[1])
lis = [[0] * C for i in range(m + 1)]
for i in stc:
    for j in range(i[0], i[1] + 1):
        lis[j][i[2] - 1] = 1
ans = 0
for i in lis:
    ans = max(ans, sum(i))
print(ans)

from collections import defaultdict
import numpy as np
import sys


sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, C = list(map(int, input().split()))
    MAX = 10 ** 5 + 2
    vals = [0] * MAX
    D = defaultdict(list)
    for _ in range(N):
        s, t, c = list(map(int, input().split()))
        D[c].append((s, t))

    for k, v in list(D.items()):
        prev = -1
        v.sort(key=lambda x: x[0])
        for s, t in v:
            if prev == s:
                vals[prev + 1] += 1
                vals[t + 1] -= 1
            else:
                vals[s] += 1
                vals[t + 1] -= 1
            prev = t

    cumsum = np.cumsum(vals)
    ans = max(cumsum)
    print(ans)


def __starting_point():
    main()

__starting_point()

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

tv = [[0]*C for _ in range(100000)]
for _ in range(N):
    s, t, c = list(map(int, input().split()))
    for i in range(s-1, t): tv[i][c-1] = 1
    
print((max([sum(tv[i]) for i in range(100000)])))


import numpy as np

n, c = list(map(int, input().split()))
stc = [[] for i in range(c+1)]
for i in range(n):
  s_, t_, c_ = list(map(int, input().split()))
  stc[c_].append([s_,t_])
  

stc_ = []
for i in range(1, c+1):
    stc[i] = sorted(stc[i], key=lambda x:(x[0], x[1]))
    j = 0
    l = len(stc[i])
    flg = False
    while j < l:
        if not flg:
            cs, ct = stc[i][j][0], stc[i][j][1]
        if j == l-1:
            stc_.append([cs, ct])
            break
        ns, nt = stc[i][j+1][0], stc[i][j+1][1]
        if ct != ns:
            flg = False
            stc_.append([cs, ct])
        else:
            flg = True
            ct = nt
            if j == l - 2:
                stc_.append([cs, ct])
                break
        j += 1
stc_ = sorted(stc_, key=lambda x:(x[0], x[1]))

m = len(stc_)

cnt = np.zeros(10**5+5, dtype=int)
for i in range(m):
    s, t = stc_[i][0]-1, stc_[i][1]
    cnt[s:t] += 1
print((cnt.max()))


N, C = map(int, input().split())
ch = [[0]*(10**5+1) for _ in range(C)]

for _ in range(N):
  s, t, c = map(int, input().split())
  ch[c-1][s] += 1
  ch[c-1][t] -= 1

for c in range(C):
  for i in range(10**5):
    if ch[c][i+1] == 1:
      ch[c][i+1] = ch[c][i+1] + ch[c][i]
      ch[c][i] = 1
    else:
      ch[c][i+1] = ch[c][i+1] + ch[c][i]

ans = 0
for i in range(10**5):
  temp = 0
  for c in range(C):
    temp += ch[c][i+1]
  ans = max(ans, temp)

print(ans)

from itertools import accumulate
n, C = list(map(int, input().split()))

U = 10**5
channels = [[0]*(U+1) for _ in range(C)]
for _ in range(n):
    s, t, c = [int(x)-1 for x in input().split()]
    channels[c][s] += 1
    channels[c][t] -= 1


for i in range(C):
    for j in range(U):
        channels[i][j+1] += channels[i][j]

schedules = [0]*(U+1)
for i in range(C):
    L = None
    for j in range(U+1):
        if channels[i][j] and L is None:
            L = j-1
            continue

        if not channels[i][j] and L is not None:
            schedules[max(L, 0)] += 1
            schedules[j] -= 1
            L = None

print((max(accumulate(schedules))))


import numpy as np

n,c = map(int,input().split())

li = np.zeros(10**5+1,int)
ch = [[] for _ in range(10**5+1)]
lin = []

for _ in range(n):
    s,t,c = map(int,input().split())
    lin.append((s,t,c))

lin.sort()

for i,j,k in lin:
    if k in ch[i-1]:
        li[i:j] += 1
        ch[j-1].append(k)
    else:
        li[i-1:j] += 1
        ch[j-1].append(k)

print(np.max(li))

N,C = map(int, input().split())
s =[0]*N
t =[0]*N
c =[0]*N
for i in range(N):
    s[i],t[i],c[i] = map(int, input().split())

imos = [[0]*int(1e5+20) for _ in range(31)]
for i in range(N):
    imos[c[i]][s[i]]+=1
    imos[c[i]][t[i]+1]-=1

ans = 0
for i in range(1,int(1e5+10)):
    sm = 0
    for j in range(31):
        imos[j][i]=imos[j][i-1]+ imos[j][i]
        if imos[j][i] >= 1:
            sm+=1
    ans = max(ans,sm)
print(ans)

from numpy import *
N,C = map(int,input().split())
A = zeros((C,10**5),int32)

for n in range(N):
  s,t,c = map(int,input().split())
  A[c-1,s-1:t] = 1
print(max(sum(A,axis=0)))

import heapq
N, C = map(int, input().split())

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

stc.sort()

lst = []
hq = [[-1, -1]]
heapq.heapify(hq)
ans = 1
for i in range(N):
    p = stc[i]
    q = heapq.heappop(hq)
    if p[0] < q[0]:
        heapq.heappush(hq, q)

        ans += 1

    elif p[0] == q[0]:
        lst = []
        jdg2 = True

        while p[0] == q[0] and p[2]>= q[1]:
            if p[2] == q[1]:

                jdg2 = False
            else:
                lst.append(q)
            if hq: q = heapq.heappop(hq)
            else: break
        if jdg2:
            ans += 1
        if p[0] != q[0] or p[2] < q[1]:
            heapq.heappush(hq, q)

        for k in lst:
            heapq.heappush(hq, k)

    heapq.heappush(hq, [p[1], p[2]])

print(ans)

N,C=map(int,input().split())
STC=[list(map(int,input().split())) for _ in range(N)]

S=[[] for _ in range(10**5+1)]
T=[[] for _ in range(10**5+1)]

for s,t,c in STC:
    S[s].append(c)
    T[t].append(c)

used=set()
ans=0
for i in range(10**5+1):
    start=set()
    finish=set()
    for s in S[i]:
        start.add(s)
    for t in T[i]:
        finish.add(t)
    ans=max(ans,len(used)+len(start-finish))
    used=used-finish|start
print(ans)

n,c = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

import numpy as np
a = np.zeros((c+1, 10**5))

for i in range(n):
    a[ab[i][2]][(ab[i][0]-1):ab[i][1]] = [1]*(ab[i][1]-ab[i][0]+1)

b = a.sum(axis=0)

print(int(max(b)))

from heapq import heappop, heappush


def main():
    n, c = list(map(int, input().split()))
    program = [[] for _ in range(c)]
    for _ in range(n):
        s, t, cc = list(map(int, input().split()))
        cc -= 1
        s *= 2
        t *= 2
        program[cc].append([s - 1, t])
    all_p = []
    for i in range(c):
        if len(program[i]) == 0:
            continue
        now = program[i]
        now.sort(key=lambda x: x[1])
        last_begin, last_end = now[0]
        for begin, end in now[1:]:
            if begin + 1 == last_end:
                last_end = end
            else:
                all_p.append([last_begin, last_end, i])
                last_begin = begin
                last_end = end
        all_p.append([last_begin, last_end, i])
    all_p.sort()
    q = [(-1, -1)]
    for begin, end, now_channel in all_p:
        last_end, last_channel = q[0]
        if last_end < begin or now_channel == last_channel:
            heappop(q)
        heappush(q, (end, now_channel))
    print((len(q)))


def __starting_point():
    main()

__starting_point()

N, C = list(map(int, input().split()))
tv = [[0]*C for _ in range(100000)]
for _ in range(N):
    s, t, c = list(map(int, input().split()))
    for i in range(s-1, t): tv[i][c-1] = 1
print((max([sum(tv[i]) for i in range(100000)])))


from collections import deque
N, C = list(map(int, input().split()))
que = []
Que = []
channel = [[] for i in range(C+1)]
for i in range(N):
    s, t, c = list(map(int, input().split()))
    channel[c].append((s, t))
for i in range(C+1):
    channel[i].sort()
    tmp_que = deque(channel[i])
    left_que = deque([])
    if tmp_que:
        x, y = tmp_que.popleft()
        left_que.append((x, y))
        while tmp_que:
            lx, ly = left_que.pop()
            rx, ry = tmp_que.popleft()
            if ly == rx:
                left_que.append((lx, ry))
            elif ly < rx:
                left_que.append((lx, ly))
                left_que.append((rx, ry))
    for x, y in left_que:
        Que.append((2*x-1, 1))
        Que.append((2*y, -1))
ans = 0
value = 0
Que.sort(reverse=True)
while Que:
    v, command = Que.pop()
    value += command
    ans = max(ans, value)
print(ans)



n, c = map(int, input().split())
imos = [0 for _ in range(10 ** 5 + 1)]
ans = 0
channel = [[] for _ in range(30)]
for _ in range(n):
    s, t, c = map(int, input().split())
    channel[c - 1].append([s, t])
    
for lst in channel:
    lst.sort()
    before = 0
    for s, t in lst:
        start = max(before, s - 1)
        imos[start] += 1
        end = min(t, 10 ** 5 + 1)
        imos[end] -= 1
        before = end
tmp = 0
for num in imos:
    tmp += num
    ans = max(ans, tmp)
print(ans)    

n, c = list(map(int, input().split()))
program = [[] for _ in range(c)]

for i in range(n):
  s, t, cc = list(map(int, input().split()))
  program[cc-1].append((s, t))

count = [0]*(10**5+1)
for i in range(c):
  program[i].sort()
  l = len(program[i])
  judge = True
  for j in range(l-1):
    if judge:
      count[program[i][j][0]-1] += 1
    if program[i][j][1] == program[i][j+1][0]:
      judge = False
    else:
      judge = True
    if judge:
      count[program[i][j][1]] -= 1
  if l == 0:
    continue
  if judge:
    count[program[i][l-1][0]-1] += 1
  count[program[i][l-1][1]] -= 1

ans = 0
for i in range(10**5+1):
  if i != 0:
    count[i] += count[i-1]
  if ans < count[i]:
    ans = count[i]
print(ans)


N , C = list(map(int,input().split()))
tel = [[0,-1] for i in range(C)]
pro = [list(map(int,input().split())) for i in range(N)]
pro.sort()
for s , t , c in pro:
    for i in range(C):
        if tel[i][0] < s - 0.5 or tel[i][1] == c or tel[i][1] == -1:
            tel[i][0] = t
            tel[i][1] = c
            break
for i in range(C):
    if tel[i][1] == -1:
        print(i)
        return
print(C)


N, C = map(int, input().split())
prog = [list(map(int, input().split())) for _ in range(N)]

#tv[i] = [t, c]
tv = [[-1, 0] for i in range(C)]

prog.sort()

for p in prog:
    s, t, c = p
    for i in range(C):
        if tv[i][0] < s - 0.5 or tv[i][1] == c or tv[i][1] == 0:
            tv[i][0] = t
            tv[i][1] = c
            break


ans = 0
for i in range(C):
    if tv[i][0] > 0:
        ans += 1
    else:
        break

print(ans)

import numpy as np
import sys
input = sys.stdin.readline

def main(args):
    N,C = map(int,input().split())
    
    time = [[0]*(10**5+1) for _ in range(C)]
    
    for _ in range(N):
        s, t, c = map(lambda x:int(x)-1,input().split())
        time[c-1][s] += 1
        time[c-1][t+1] -= 1
        
    recorder = np.where(np.cumsum(time[0]) > 0, 1, 0)
    
    for i in range(1,C):
        recorder += np.where(np.cumsum(time[i]) > 0, 1, 0)
    
    print(max(recorder))
    
def __starting_point():
    main(sys.argv[1:])
__starting_point()

import sys
import numpy as np
readline=sys.stdin.readline
read=sys.stdin.read

n,c,*stc=list(map(int,read().split()))
m=2*10**5
cht=np.zeros((c,m+1),dtype='int64')
for s,t,ch in zip(*[iter(stc)]*3):
  cht[ch-1,2*s-1:2*t]=np.ones(2*t-2*s+1)
print((max(np.sum(cht,axis=0))))


import numpy as np
N,C=list(map(int, input().split()))

#s~tでc
L=np.zeros((C, 10**5+1))

for i in range(N):
    s,t,c=list(map(int, input().split()))
    L[c-1,s-1]+=1
    L[c-1,t]-=1

L=np.cumsum(L, axis=1)
print((int((L>0).sum(axis=0).max())))


import sys

input = sys.stdin.readline


def main():
    N, C = [int(x) for x in input().split()]
    STC = [[int(x) for x in input().split()] for _ in range(N)]

    S = [[] for _ in range(10 ** 5 + 1)]
    T = [[] for _ in range(10 ** 5 + 1)]

    for s, t, c in STC:
        S[s].append(c)
        T[t].append(c)

    used = set()
    ans = 0
    for i in range(10 ** 5 + 1):
        sused = set()
        tused = set()

        for s in S[i]:
            sused.add(s)
        for t in T[i]:
            tused.add(t)

        ans = max(ans, len(used) + len(sused - tused))
        used = used - tused | sused

    print(ans)








def __starting_point():
    main()

__starting_point()

ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
N,C = ma()
nn = 10**5+4
times = [[0 for i in range(nn)] for j in range(C+1)]
for i in range(N):
    s,t,c = ma()
    times[c][s] +=1
    times[c][t] -=1
for c in range(1,C+1):
    for i in range(nn-1):
        times[c][i+1] += times[c][i]

tot = [0 for i in range(nn)]
for c in range(C+1):
    for i in range(nn-1):
        tot[i] += times[c][i]
        if times[c][i] == 0 and times[c][i+1] ==1:
            tot[i] +=1
print(max(tot))


import sys
import numpy as np
readline=sys.stdin.readline
read=sys.stdin.read

n,c=list(map(int,readline().split()))
m=2*10**5
stc=[list(map(int,l.split())) for l in read().splitlines()]
cht=np.zeros((c,m+1),dtype='int64')
for e in stc:
  cht[e[2]-1,2*e[0]-1:2*e[1]]=np.ones(2*e[1]-2*e[0]+1)
print((max(np.sum(cht,axis=0))))


import numpy as np

def main():
    with open(0) as f:
        N, C = list(map(int, f.readline().split()))
        Rec = [tuple(map(int, f.readline().split())) for _ in range(N)]
    
    time_line_by_channel = np.array([[0] * (10**5+1) for _ in range(C+1)])
    #チャンネルごとにタイムラインを作成
    for s, t, c in Rec:
        time_line_by_channel[c, s-1:t] = 1
    #タイムライン結合
    joined_timeline = np.sum(time_line_by_channel, axis=0)
    ans = max(joined_timeline)
    print(ans)

main()


import sys
input = sys.stdin.readline
n,C = map(int,input().split())
ch = [[] for _ in range(C)]
tmax = 0
for _ in range(n):
  s,t,c = map(int,input().split())
  ch[c-1].append((s,t))
  tmax = max(tmax,t)
ch = [sorted(i,key= lambda x:x[0]) for i in ch]
imos = [0]*(tmax+2)
for i in ch:
  now = -1
  for ds,dt in i:
    if ds == now:
      imos[ds] +=1
    else:
      imos[ds-1] += 1
    imos[dt] -= 1
    now = dt
for i in range(tmax +1):
  imos[i+1] += imos[i]
print(max(imos))

import heapq
N, C, *STC = [int(_) for _ in open(0).read().split()]
STC = [(s, t, c) for s, t, c in zip(STC[::3], STC[1::3], STC[2::3])]
STC.sort()
#もしcを映しているテレビがあるならこれにしてしまうのが最適
#cを映しているテレビがないならすでに終わっているテレビのどれかを選ぶ
#どのテレビもすでに映しているなら新しいテレビを追加する

class SegmentTree():
    def __init__(self, array, f, ti):
        """
        Parameters
        ----------
        array : list
            to construct segment tree from
        f : func
            binary operation of the monoid
        ti : 
            identity element of the monoid
        """
        self.f = f
        self.ti = ti
        self.n = n = 2**(len(array).bit_length())
        self.dat = dat = [ti] * n + array + [ti] * (n - len(array))
        for i in range(n - 1, 0, -1):  # build
            dat[i] = f(dat[i << 1], dat[i << 1 | 1])

    def update(self, p, v):  # set value at position p (0-indexed)
        f, n, dat = self.f, self.n, self.dat
        p += n
        dat[p] = v
        while p > 1:
            p >>= 1
            dat[p] = f(dat[p << 1], dat[p << 1 | 1])

    def operate_right(self, p, v):  # apply operator from the right side
        f, n, dat = self.f, self.n, self.dat
        p += n
        dat[p] = f(dat[p], v)
        while p > 1:
            p >>= 1
            dat[p] = f(dat[p << 1], dat[p << 1 | 1])

    def operate_left(self, p, v):  # apply operator from the left side
        f, n, dat = self.f, self.n, self.dat
        p += n
        dat[p] = f(v, dat[p])
        while p > 1:
            p >>= 1
            dat[p] = f(dat[p << 1], dat[p << 1 | 1])

    def query(self, l, r):  # result on interval [l, r) (0-indexed)
        f, ti, n, dat = self.f, self.ti, self.n, self.dat
        vl = vr = ti
        l += n
        r += n
        while l < r:
            if l & 1:
                vl = f(vl, dat[l])
                l += 1
            if r & 1:
                r -= 1
                vr = f(dat[r], vr)
            l >>= 1
            r >>= 1
        return f(vl, vr)

ti = (10 ** 10, -10 ** 10)
st = SegmentTree([(10 ** 10, i) for i in range(C + 1)], min, ti)
ans = 0
for s, t, c in STC:
    if st.query(c, c + 1)[0] == 10 ** 10:
        t2, c2 = st.query(1, C + 1)
        if t2 < s:
            st.update(c2, (10 ** 10, c2))
        else:
            ans += 1
    st.update(c, (t, c))
print(ans)


import numpy as np
N, C = map(int,input().split())
T1 = [[] for _ in range(C)]
for _ in range(N):
    s, t, c = map(int,input().split())
    T1[c-1].append([s,t])
for i in range(C):
    T1[i].sort()
T2 = [[] for _ in range(C)]
for i in range(C):
    for s, t in T1[i]:
        if len(T2[i]) != 0 and T2[i][-1][1] == s:
            T2[i][-1][1] = t
        else:
            T2[i].append([s,t])

L = np.zeros(10 ** 5 + 2, int)
for i in range(C):
    for time in T2[i]:
        L[time[0]] += 1
        L[time[1]+1] -= 1

ans = L.cumsum().max()

print(ans)

n,c=map(int,input().split())
t=[[0 for i in range(100001)] for j in range(c)]

for i in range(n):
    si,ti,ci = map(int,input().split())
    for j in range(si,ti+1):
        t[ci-1][j] = 1
print(max(sum(t[j][i] for j in range(c)) for i in range(100001)))

from itertools import accumulate


def main():
    n, c = list(map(int, input().split()))
    p = [[] for _ in range(c + 1)]
    for _ in range(n):
        *st, cc = list(map(int, input().split()))
        p[cc].append(st)
    all_p = [0] * (10 ** 5 + 10)
    for pp in p:
        if len(pp) == 0:
            continue
        pp.sort()
        last_start, last_end = pp[0]
        for start, end in pp[1:]:
            if start == last_end:
                last_end = end
            else:
                all_p[last_start - 1] += 1
                all_p[last_end] -= 1
                last_start, last_end = start, end
        all_p[last_start - 1] += 1
        all_p[last_end] -= 1
    print((max(accumulate(all_p))))


def __starting_point():
    main()

__starting_point()

# ある時点の重複番組数を前からカウントして、最大値が答え
# s順に並べて、ループごとに重複数を増やしつつ、
# 終了キューにtを追加
# 番組追加するごとに終了キューの中身をチェック
# 同じチャンネルだったら、終了キューt <= 現在時刻 のときに終了キューから外せる
# 違うチャンネルだったら、終了キューt < 現在時刻となる
# チャンネルごとにheapqを持つ

N,C = map(int,input().split())
import heapq
endq = [[] for i in range(C)]
for i in range(C):
  heapq.heapify(endq[i])
progs = [None] * N
for i in range(N):
  s,t,c = map(int,input().split())
  progs[i] = [s,t,c-1]

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

ans = 0
cur = 0

for i in range(N):
  s,t,c = progs[i]
  # 時刻sに終了する番組をチェックする
  # まず同チャンネルのものが時刻sに終了していたら、それを外すことが出来る
  while endq[c]:
    endt = heapq.heappop(endq[c])
    if endt <= s:
      cur -= 1
    else:
      heapq.heappush(endq[c],endt)
      break
  
  # 他のチャンネルをチェックする
  for endc in range(C):
    if endc == c:
      continue # 同じチャンネルはチェック済み
    while endq[endc]:
      endt = heapq.heappop(endq[endc]) # 各チャンネルのキューから取り出す
      if endt < s:
        cur -= 1
      else:
        heapq.heappush(endq[endc],endt)
        break
  # 今回の番組を格納する
  cur += 1
  heapq.heappush(endq[c],t)
  if cur > ans:
    ans = cur

print(ans)

# 解説 imos
n, C = map(int, input().split())
L = [tuple(map(int, input().split())) for _ in range(n)]
m = 10 ** 5
S = [0] * m
for i in range(1, C + 1):
    T = [0] * (m + 1)
    for s, t, c in L:
        if c == i:
            T[s - 1] += 1
            T[t] -= 1
    for i in range(m):
        T[i + 1] += T[i]
    for i in range(m):
        S[i] += T[i] > 0
print(max(S))

import numpy as np
N, C = (int(x) for x in input().split())
R = [[0]*100000 for _ in range(C)] #R[c][t]:時刻t+1にチャンネルc+1を録画するのに必要な録画機の個数
R = np.array(R)
for _ in range(N):
    s, t, c = map(int,input().split())
    R[c-1,s-1:t] = 1
ans = max(sum(R))
print(ans)

n,c = list(map(int,input().split()))

l = [[] for i in range(c)]
for i in range(n):
    s,t,x = list(map(int,input().split()))
    l[x-1].append([s,t])

al= []
for i in range(c):
    if len(l[i]) > 1:
        l[i].sort()
        now2 = l[i][0][1]
        now1 = l[i][0][0]
        check = False
        for j in range(1,len(l[i])):
            if l[i][j][0] == now2:
                now2 = l[i][j][1]
            else:
                al.append([[now1,now2],i])
                check = True
                now1 = l[i][j][0]
                now2 = l[i][j][1]
        if not check:
            al.append([[now1,now2],i])

    else: 
        if l[i]:
            al.append([l[i][0],i])
al.sort()

count = [[-1,-1]]
for i in range(len(al)):
    a,b,c = al[i][0][0], al[i][0][1],al[i][1]
    check = False
    for j in range(len(count)):
        if count[j][0] < a:
            count[j] = [b,c]
            check = True
            break
    if not check:
        count.append([b,c])

print((len(count)))


n,c=map(int,input().split())
chan=[[] for _ in range(c)]
for _ in range(n):
    s,t,sc=map(int,input().split())
    sc-=1
    chan[sc].append((s,t))
for i in range(c):
    chan[i].sort()
#print(chan)
for i in range(c):
    lis=[]
    if len(chan[i])==1:
        lis.append(chan[i][0][0])
        lis.append(chan[i][0][1])
    elif len(chan[i])>=2:
        lis.append(chan[i][0][0])
        for j in range(len(chan[i])-1):
            if chan[i][j][1]!=chan[i][j+1][0]:
                lis.append(chan[i][j][1])
                lis.append(chan[i][j+1][0])
        lis.append(chan[i][j+1][1])
    chan[i]=lis
#print(chan)
accum=[0]*(10**5+2)
for i in range(c):
    for j in range(0,len(chan[i])-1,2):
        accum[chan[i][j]]+=1
        accum[chan[i][j+1]+1]-=1
for i in range(10**5+1):
    accum[i+1]+=accum[i]
#print(accum)
print(max(accum))

# solution

import io
import sys
import math
from itertools import accumulate as acc

data=sys.stdin.readline

N,C=map(int,data().split())


array=[[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=map(int,data().split())
    recs,rect=array[c][s],array[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

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

tmp=0
ans=0
for i in range(10**5):
    tmp+=rec[i]
    ans=max(tmp,ans)
print(ans)

import itertools

N, C = list(map(int, input().split()))
MAX = 10 ** 5 + 1
table = [[0] * MAX for _ in range(C)]

for _ in range(N):
    s, t, c = list(map(int, input().split()))
    c -= 1
    table[c][s] += 1
    table[c][t] -= 1

for c in range(C):
    for x in range(MAX - 1):
        if table[c][x + 1] == 1:
            table[c][x + 1] = 0
            table[c][x] += 1

table_sum = [sum(table[c][i] for c in range(C)) for i in range(MAX)]
print((max(itertools.accumulate(table_sum))))


# 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)))


def __starting_point():
    main()

__starting_point()

import sys

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

# 同一チャンネルならtとsが連続していても1台で録画できる
# そのため、通常のimos法ではなく、録画開始・終了のチャンネルを保持する
times = [[set() for _ in range(10**5 + 5)], [set() for _ in range(10**5 + 5)]]
max_t = 0
for _ in range(N):
    s, t, c = map(int, sys.stdin.readline().split())
    # 基本的にs-1だけでよいが、同一チャンネルで録画が連続する場合の対応を入れておく
    times[0][s-1].add(c)
    times[0][s].add(c)
    times[1][t].add(c)
    max_t = max(max_t, t)

ans = 0
recording = set()
for i in range(max_t + 5):
    recording -= times[1][i]
    recording |= times[0][i]
    ans = max(ans, len(recording))

print(ans)

import numpy as np
N, C = map(int, input().split())
s = np.empty(N)
t = np.empty(N)
c = np.empty(N)
for i in range(N):
  s[i], t[i], c[i] =  map(int, input().split())
TimeTable = np.zeros((C,100001))
maxTime = 0
for i in range(N):
  channle = int(c[i] - 1)
  for j in range(int(s[i]),int(t[i])+1):
    TimeTable[channle,j] = 1
  if maxTime < t[i]:
    maxTime = t[i]
MaxRecode = 0
for i in range(int(maxTime)):
  Recode = np.sum(TimeTable[:,i])
  if Recode > MaxRecode:
    MaxRecode = Recode
print(int(MaxRecode))

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

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

for i in range(N):
    s,t,c=map(int,input().split())
    old[c-1].append((s,t))
ch=[]
for li in old:
    li.sort()
    j=0
    while(j<len(li)):
        start=li[j][0]
        while(j<len(li)-1 and li[j][1]==li[j+1][0]):
            j+=1
        end=li[j][1]
        ch.append((((start-1)*2)+1,end*2))
        j+=1
    
        
imos=[0]*(2*10**5+10)
for s,t in ch:
    imos[s]+=1
    imos[t]-=1
for i in range(1,2*10**5+10):
    imos[i]=imos[i-1]+imos[i]
print(max(imos))

import heapq

def main():
    N, C = list(map(int, input().split()))
    STC = [tuple(map(int, input().split())) for _ in range(N)]
    STC.sort()
    CC = [(0, 0)] * C
    T = []
    for s, t, c in STC:
        ps, pt = CC[c - 1]
        if ps == 0:
            CC[c - 1] = (s, t)
        elif s == pt:
            CC[c - 1] = (ps, t)
        else:
            T.append((ps, pt, c))
            CC[c - 1] = (s, t)
    for c, (s, t) in enumerate(CC):
        if s != 0:
            T.append((s, t, c + 1))
    T.sort()
    STC = T

    h = []
    e = []
    r = 0
    for s, t, c in STC:
        while h and h[0][0] <= s:
            e.append(heapq.heappop(h)[1])
        if not e:
            e.append(r)
            r += 1
        heapq.heappush(h, (t + 1, e.pop()))
    return r

print((main()))


A,B=list(map(int,input().split()))
l=[[] for i in range(100001)]
for i in range(A):
   X,Y,Z=list(map(int,input().split()))
   for j in range(X-1,Y):
      l[j].append(Z)
ans=0
for i in l:
   ans=max(ans,len(set(i)))
print(ans)

# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap



@mt
def slv(N, C, STC):
    from collections import Counter
    se = [(2*s, 0, c) for s, t, c in STC]
    te = [(2*t+1, 1, c) for s, t, c in STC]
    e = se + te
    e.sort(reverse=True)
    r = Counter()
    ans = 0
    while e:
        _, k, c = e.pop()
        if k == 0:
            r[c] += 1
        else:
            r[c] -= 1
            if r[c] == 0:
                r.pop(c)
        ans = max(ans, len(r))
    return ans


def main():
    N, C = read_int_n()
    STC = [read_int_n() for _ in range(N)]
    print(slv(N, C, STC))


def __starting_point():
    main()

__starting_point()

import sys
import numpy as np
input = sys.stdin.readline
n,C = map(int,input().split())
a = np.zeros((C,10**5),dtype="int")
for _ in range(n):
  s,t,c = map(int,input().split())
  a[c-1,s-1:t] = 1
print(max(np.sum(a,axis=0)))

def main():
    import sys
    input = sys.stdin.readline
    from heapq import heappush
    N, C = map(int, input().split())
    table = [[0]*10**5 for _ in range(C)]
    for _ in range(N):
        s, t, c = map(int, input().split())
        s -= 1
        t -= 1
        c -= 1
        for i in range(s, t + 1):
            table[c][i] = 1
            
    ans = 0
    for i in range(10**5):
        tmp = sum(table[j][i] for j in range(C))
        ans = max(ans, tmp)
    print(ans)


def __starting_point():
    main()
__starting_point()

N,C = map(int, input().split())
s =[0]*N
t =[0]*N
c =[0]*N
for i in range(N):
    s[i],t[i],c[i] = map(int, input().split())

imos = [[0]*int(1e5+20) for _ in range(31)]
for i in range(N):
    imos[c[i]][s[i]]+=1
    imos[c[i]][t[i]+1]-=1

ans = 0
for i in range(1,int(1e5+10)):
    sm = 0
    for j in range(C+1):
        imos[j][i]=imos[j][i-1]+ imos[j][i]
        if imos[j][i] >= 1:
            sm+=1
    ans = max(ans,sm)
print(ans)

def Recording():
    n, c = list(map(int, input().split()))
    num = 2*10**5+1 

    # チャンネルごとにimos配列
    imos = [[0]*num for _ in range(c)]
    
    # imos
    for _ in range(n):
        s, t, c0 = list(map(int, input().split()))
        if imos[c0-1][s*2] < 0 and imos[c0-1][t*2-1] > 0:
            imos[c0-1][s*2] = 0
            imos[c0-1][t*2-1] = 0
        elif imos[c0-1][s*2] < 0:            
            imos[c0-1][s*2] = 0
            imos[c0-1][t*2] -= 1
        elif imos[c0-1][t*2-1] > 0:    
            imos[c0-1][s*2-1] += 1
            imos[c0-1][t*2-1] = 0
        else:
            imos[c0-1][s*2-1] += 1
            imos[c0-1][t*2] -= 1
    ans = [0 for _ in range(num)]
    for i in range(c):
        for j in range(1, num):
            imos[i][j] += imos[i][j-1]
            ans[j] += imos[i][j]
    print((max(ans)))
    
def __starting_point():
    Recording()
    

__starting_point()

# 1-index
from sys import stdin
import numpy as np
N, C = [int(x) for x in stdin.readline().rstrip().split()]
imos = np.array([[0]*(10**5+1) for i in range(C+1)])

for i in range(N):
    s, t, c = [int(x) for x in stdin.readline().rstrip().split()]
    imos[c, s - 1:t] = 1

imos = np.array(imos)
# print(np.cumsum(imos,axis=1))
ans = max(imos.sum(axis=0))
print(ans)

import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  N,C=LI()
  l=[[0]*100100 for _ in range(C)]

  for _ in range(N):
    s,t,c=LI()
    l[c-1][s]+=1
    l[c-1][t+1]-=1

  for i in range(C):
    for j in range(100000):
      l[i][j+1]+=l[i][j]

  for i in range(C):
    for j in range(100000):
      if l[i][j]==2:
        l[i][j]=1

  mx=0
  for i in range(100000):
    sm=0
    for j in range(C):
      sm+=l[j][i]
    mx=max(mx,sm)

  return mx

# main()
print((main()))


# https://atcoder.jp/contests/abc080/tasks/abc080_d
# D - Recording

N,C = list(map(int,input().split()))
s=[0]*N
t=[0]*N
c=[0]*N
f=[False]*C
yoyaku=[False]*C
L=[]
for i in range(N):
    s[i],t[i],c[i]= list(map(int,input().split()))
    L.append( [s[i]-0.5,c[i]-1,1] )
    L.append( [t[i],c[i]-1,0] )

L.sort()
#print(L)
ans=0
tmp=0

for i,(time, ch, sw) in enumerate(L):
    if sw==1:
        if f[ch]==False:
            tmp +=1
            f[ch]=True
            ans = max(ans,tmp)
        else:
            yoyaku[ch]=True
    else:
        if yoyaku[ch]:
            yoyaku[ch]=False
        else:
            tmp -= 1
            f[ch]=False
   
print(ans)


import itertools
N,C=list(map(int,input().split()))
ch =[[] for _ in range(C+1)]
time= [0]*(10**5+1)
for _ in range(N):
    s,t,c=list(map(int,input().split()))
    ch[c].append(s)
    ch[c].append(t)
    
for i in range(1,C+1):
    ch[i].sort()

for i in range(1,C+1):
    for chi in range(len(ch[i])):
        if chi %2 == 0:
            if chi == 0:
                time[ch[i][chi]-1]+=1
            elif chi>1 and ch[i][chi-1]!=ch[i][chi]:
                time[ch[i][chi]-1]+=1
        elif chi %2 == 1:
            if chi==len(ch[i])-1:
                time[ch[i][chi]]-=1
            elif ch[i][chi+1] != ch[i][chi]:
                time[ch[i][chi]]-=1

integ_time = itertools.accumulate(time)
print((max(integ_time)))


n,c,*stc = list(map(int,open(0).read().split()))
stc = list(zip(stc[::3],stc[1::3],stc[2::3]))

stc.sort()

record = []

for s,t,c in stc:
    
    for i,(rt,rc) in enumerate(record):
        if s-0.5 >= rt:
            record[i] = (t,c)
            break
        elif c == rc and  s>= rt:
            record[i] = (t,c)
            break
    else:
        record.append((t,c))
    
    record.sort(reverse=True)

print((len(record)))


#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)

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

C = 30
st = [[] for i in range(C)]

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

data = [0]*(10**5*2)
for i in range(C):
    data_tmp = [0]*(10**5*2)
    for j in range(len(st[i])):
        s, t = st[i][j]

        start = max(s*2, 0)
        end = min((t-1)*2+1, 10**5*2-1)
        data_tmp[start] += 1
        data_tmp[end+1] -= 1
    # print(data_tmp[:30])
    for j in range(1, len(data_tmp)-1):
        if data_tmp[j] > 0:
            data_tmp[j-1] += data_tmp[j]
            data_tmp[j] = 0
    # for j in reversed(range(1, len(data_tmp)-1)):
    #     if data_tmp[j] < 0:
    #         data_tmp[j+1] += data_tmp[j]
    #         data_tmp[j] = 0
    for j in range(0, len(data_tmp)):
        data[j] += data_tmp[j]
    # print(data_tmp[:30])
    # print()
ans = [data[0]]
for i in range(1, len(data)):
    ans.append(ans[-1]+data[i])

print((max(ans)))


import sys
from collections import *
import heapq
import math
# from math import gcd
import bisect
import copy
from itertools import permutations,accumulate,combinations,product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,c=map(int,input().split())
stc=[list(map(int,input().split())) for i in range(n)]
stc.sort()
lst=[0]*c
for i in range(n):
    s,t,ctmp=stc[i]
    for j in range(c):
        if lst[j]==0:
            lst[j]=stc[i]
            break
        else:
            if lst[j][2]==ctmp:
                lst[j]=stc[i]
                break
            elif lst[j][1]<s:
                lst[j]=stc[i]
                break
# print(lst)
ans=0
for i in range(c):
    if lst[i]!=0:
        ans+=1
print(ans)

from operator import itemgetter
def resolve():
    N, C = list(map(int, input().split()))
    STC = sorted([list(map(int, input().split())) for _ in range(N)], key=itemgetter(2, 0))
    
    counts = [0]*(10**5+1)
    prevt, prevc = -1, -1
    for stc in STC:
        s, t, c = stc
        if prevt == s and prevc == c:
            counts[s] += 1
        else:
            counts[s - 1] += 1
        counts[t] -= 1
        prevt, prevc = t, c
    for i in range(1, 10**5+1):
        counts[i] += counts[i-1]
    #print(counts[:15])
    print(max(counts))


if '__main__' == __name__:
    resolve()

N, C = map(int, input().split())
table = [[0]*(10**5 + 1) for i in range(C)]

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

st_new = [[] for i in range(C)]
for c in range(C):
  if st[c]:
    st[c].sort()
    st_new[c].append(st[c][0])
    n = len(st[c])
    for i in range(1, n):
      si, ti = st[c][i]
      sii, tii = st_new[c][-1]
      if si == tii:
        st_new[c][-1][1] = ti
      else:
        st_new[c].append([si, ti])

for c in range(C):
  for s, t in st_new[c]:
    table[c][s-1] += 1
    table[c][t] -= 1
  
for c in range(C):
  for i in range(1, 10**5+1):
    table[c][i] += table[c][i-1]

ans = 0
for i in range(10**5 + 1):
  num = 0
  for c in range(C):
    num += table[c][i]
  ans = max(ans, num)

print(ans)

class Imos:
    def __init__(self, n):
        self.B = [0] * n
        self.n = n
        from itertools import accumulate
        self.ac = accumulate

    def __call__(self, l, r):
        l, r = max(l, 0), min(r, self.n - 1)
        self.B[l] += 1
        self.B[r + 1] -= 1

    def out(self):
        *res, = self.ac(self.B)
        # self.__init__(self.n)
        return res

from collections import defaultdict
d = defaultdict(list)
imos = Imos(10 ** 5 + 1)

(N, C), *D = [[*map(int, o.split())] for o in open(0)]
for s, t, c in D:
    d[c] += (s, t),
for p in d.values():
    p.sort()
    ps, pt = p[0]
    for s, t in p[1:] + [[0,0]]:
        if pt == s:
            pt = t
        else:
            imos(ps - 1, pt - 1)
            ps, pt = s, t
print(max(imos.out()))

n,C=map(int,input().split())

chs=[[] for i in range(31)]

for i in range(n):
    s,t,c=map(int,input().split())
    chs[c].append((s,t))

for q in range(len(chs)):
    ch=chs[q][:]
    ch.sort()
    new=[]
    if len(ch)<=1:
        continue
    else:
        now=ch[0]
        for i in range(1,len(ch)):
            if now[1]==ch[i][0]:
                now=(now[0],ch[i][1])
            else:
                new.append(now)
                now=ch[i]
        new.append(now)
        chs[q]=new[:]

tim=[0 for i in range(200002)]

for ch in chs:
    for pro in ch:
        tim[pro[0]*2-1]+=1
        tim[pro[1]*2]-=1

cnt=0
ans=0
for i in range(len(tim)):
    cnt+=tim[i]
    ans=max(ans,cnt)
print(ans)

class Imos:
    def __init__(self, n):
        self.B = [0] * n
        self.n = n
        from itertools import accumulate
        self.ac = accumulate

    def __call__(self, l, r):
        l, r = max(l, 0), min(r, self.n - 1)
        self.B[l] += 1
        if r + 1 != self.n:
            self.B[r + 1] -= 1

    def out(self):
        *res, = self.ac(self.B)
        self.__init__(self.n)
        return res

from collections import defaultdict
d = defaultdict(list)
imos = Imos(10 ** 5 + 1)

(N, C), *D = [[*map(int, o.split())] for o in open(0)]
for s, t, c in D:
    d[c] += (s, t),
for p in d.values():
    p.sort()
    ps, pt = p[0]
    for s, t in p[1:] + [[0,0]]:
        if pt == s:
            pt = t
        else:
            imos(ps - 1, pt - 1)
            ps, pt = s, t
print(max(imos.out()))

from collections import defaultdict as dd
N, C = tuple(map(int, input().split()))
events = []
tmax = 0
dic=dd(list)
for i in range(N):
    s, t, c = map(int, input().split())
    dic[c].append((s,t))
eps = 0.5
for k,v in dic.items():
    v1 = sorted(v)
    lev = len(v1)
    prev = [-1,-1]
    for i,val in enumerate(v1):
        if tmax < val[1]:
            tmax = val[1]
        if prev == [-1,-1]:
            prev[0] = val[0]
            prev[1] = val[1] # end_time
            if lev != 1:
                continue
            else:
                events.append((prev[0]-eps, 1))
                events.append((prev[1], 0))
                break
        if prev[1] == val[0]:# prev_end == now_start
            prev[1] = val[1]
            if i == lev - 1:
                events.append((prev[0] - eps, 1))
                events.append((prev[1], 0))
                break
        else:
            events.append((prev[0]-eps, 1))
            events.append((prev[1], 0))
            prev[0] = val[0]
            prev[1] = val[1]
            if i==lev-1:
                events.append((val[0]-eps, 1))
                events.append((val[1], 0))
                break
events.sort()
idx = 0
cnt = 0
res = 0
events.append((0,-1))
for t in range(tmax + 1):
    while events[idx][0] <= t:
        event = events[idx]
        if event[1] == 1:
            cnt += 1
            if res < cnt:
                res = cnt
        elif event[1] == 0:
            cnt -= 1
        else:
            break
        idx += 1
print(res)

import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, c = list(map(int, input().split()))
    STC = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x:[x[2], x[0]])

    STC2 = []
    tmp = STC[0]
    for i in range(1, n):
        pre_s, pre_t, pre_c = tmp
        now_s, now_t, now_c = STC[i]
        if pre_c == now_c:
            if pre_t == now_s:
                tmp = [pre_s, now_t, now_c]
            else:
                STC2.append(tmp)
                tmp = STC[i]
        else:
            STC2.append(tmp)
            tmp = STC[i]
    if len(tmp):
        STC2.append(tmp)

    imos = [[0] * (10 ** 5 + 1) for _ in range(c)]
    for i in range(len(STC2)):
        s, t, c = STC2[i]
        imos[c - 1][s - 1] += 1
        imos[c - 1][t] -= 1

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

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

    print((max(res)))


def __starting_point():
    resolve()

__starting_point()

from itertools import accumulate

MAX_T = 10 ** 5 + 100
MAX_C = 30

n, c = list(map(int, input().split()))
time = {c: [] for c in range(1, MAX_C + 1)}

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

n_program = [0 for _ in range(MAX_T + 1)]

for c in range(1, MAX_C + 1):

    recording = [0 for _ in range(MAX_T + 1)]

    for s, t in time[c]:
        recording[s] += 1
        recording[t + 1] -= 1

    recording = accumulate(recording)

    for i, r in enumerate(recording):
        if r:
            n_program[i] += 1

answer = max(n_program)
print(answer)


# 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)


def __starting_point():
    main()

__starting_point()

n,c = map(int,input().split())

t = [[0 for i in range(100001)] for j in range(c)]

for i in range(n):
    si,ti,ci = map(int,input().split())
    for j in range(si,ti+1):
        t[ci-1][j] = 1
ans = 0
for i in range(100001):
    ans = max(ans,sum(t[j][i] for j in range(c)))
print(ans)

import sys
readline=sys.stdin.readline
read=sys.stdin.read

n,c=list(map(int,readline().split()))
m=2*10**5
stc=[list(map(int,l.split())) for l in read().splitlines()]
cht=[[0]*(m+1) for _ in range(c)]
for e in stc:
  cht[e[2]-1][2*e[0]-1:2*e[1]]=[1 for _ in range(2*e[1]-2*e[0]+1)]
mnr=0
for i in range(1,m+1):
  mnr=max(mnr,sum(cht[ch][i] for ch in range(c)))
print(mnr)


import sys
import numpy as np
readline=sys.stdin.readline
read=sys.stdin.read

def main():
  n,c=map(int,readline().split())
  m=2*10**5
  stc=[list(map(int,l.split())) for l in read().splitlines()]
  cht=np.zeros((c,m+1),dtype='int64')
  for e in stc:
    cht[e[2]-1,2*e[0]-1:2*e[1]]=np.ones(2*e[1]-2*e[0]+1)
  print(max(np.sum(cht,axis=0)))

def __starting_point():
  main()
__starting_point()