import sys

stdin = sys.stdin



sys.setrecursionlimit(10**5) 

 

def li(): return list(map(int, stdin.readline().split()))

def li_(): return [int(x)-1 for x in stdin.readline().split()]

def lf(): return list(map(float, stdin.readline().split()))

def ls(): return stdin.readline().split()

def ns(): return stdin.readline().rstrip()

def lc(): return list(ns())

def ni(): return int(stdin.readline())

def nf(): return float(stdin.readline())



from itertools import accumulate



N,C = li()

MAX = 10**5



stc = []

for _ in range(N):

    stc.append(list(li()))

    

rec = [[0 for _ in range(MAX+1)] for _ in range(C)]

for s,t,c in stc:

    rec[c-1][s-1] += 1

    rec[c-1][t] -= 1

    

for i in range(C):

    rec[i] = list(accumulate(rec[i]))

    rec[i] = [min(1,reci) for reci in rec[i]]

    

rec_total = rec[0]

    

for i in range(1,C):

    for j in range(MAX+1):

        rec_total[j] = rec_total[j] + rec[i][j]



print((max(rec_total)))
import sys

stdin = sys.stdin

 

sys.setrecursionlimit(10**5) 

 

def li(): return list(map(int, stdin.readline().split()))

def li_(): return [int(x)-1 for x in stdin.readline().split()]

def lf(): return list(map(float, stdin.readline().split()))

def ls(): return stdin.readline().split()

def ns(): return stdin.readline().rstrip()

def lc(): return list(ns())

def ni(): return int(stdin.readline())

def nf(): return float(stdin.readline())



from itertools import accumulate



n,ch = li()

MAX_T = 10**5+1



program = [[0]*MAX_T for _ in range(ch)]



endset = [set() for _ in range(ch)]

stc = []



for _ in range(n):

    s,t,c = li()

    c -= 1

    

    stc.append((s,t,c))

    endset[c].add(t)

    

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

    

for s,t,c in stc:

    if s in endset[c]:

        program[c][s] += 1

        program[c][t] -= 1

    else:

        program[c][s-1] += 1

        program[c][t] -= 1

    

for ci in range(ch):

    program[ci] = list(accumulate(program[ci]))

    

print((max([sum(time_span) for time_span in zip(*program)])))

import sys

stdin = sys.stdin
sys.setrecursionlimit(10**5)


def li():
    return list(map(int, stdin.readline().split()))


def li_():
    return [int(x) - 1 for x in stdin.readline().split()]


def lf():
    return list(map(float, stdin.readline().split()))


def ls():
    return stdin.readline().split()


def ns():
    return stdin.readline().rstrip()


def lc():
    return list(ns())


def ni():
    return int(stdin.readline())


def nf():
    return float(stdin.readline())


from itertools import accumulate

N, C = li()
MAX = 10**5
stc = []
for _ in range(N):
    stc.append(list(li()))
rec = [[0 for _ in range(MAX + 1)] for _ in range(C)]
for s, t, c in stc:
    rec[c - 1][s - 1] += 1
    rec[c - 1][t] -= 1
for i in range(C):
    rec[i] = list(accumulate(rec[i]))
    rec[i] = [min(1, reci) for reci in rec[i]]
rec_total = rec[0]
for i in range(1, C):
    for j in range(MAX + 1):
        rec_total[j] = rec_total[j] + rec[i][j]
print((max(rec_total)))

import sys

stdin = sys.stdin
sys.setrecursionlimit(10**5)


def li():
    return list(map(int, stdin.readline().split()))


def li_():
    return [int(x) - 1 for x in stdin.readline().split()]


def lf():
    return list(map(float, stdin.readline().split()))


def ls():
    return stdin.readline().split()


def ns():
    return stdin.readline().rstrip()


def lc():
    return list(ns())


def ni():
    return int(stdin.readline())


def nf():
    return float(stdin.readline())


from itertools import accumulate

n, ch = li()
MAX_T = 10**5 + 1
program = [[0] * MAX_T for _ in range(ch)]
endset = [set() for _ in range(ch)]
stc = []
for _ in range(n):
    s, t, c = li()
    c -= 1
    stc.append((s, t, c))
    endset[c].add(t)
stc.sort(key=lambda x: x[0])
for s, t, c in stc:
    if s in endset[c]:
        program[c][s] += 1
        program[c][t] -= 1
    else:
        program[c][s - 1] += 1
        program[c][t] -= 1
for ci in range(ch):
    program[ci] = list(accumulate(program[ci]))
print((max([sum(time_span) for time_span in zip(*program)])))

-N, C = li() -MAX = 10**5 +n, ch = li() +MAX_T = 10**5 + 1 +program = [[0] * MAX_T for _ in range(ch)] +endset = [set() for _ in range(ch)] -for _ in range(N): -    stc.append(list(li())) -rec = [[0 for _ in range(MAX + 1)] for _ in range(C)] +for _ in range(n): +    s, t, c = li() +    c -= 1 +    stc.append((s, t, c)) +    endset[c].add(t) +stc.sort(key=lambda x: x[0]) -    rec[c - 1][s - 1] += 1 -    rec[c - 1][t] -= 1 -for i in range(C): -    rec[i] = list(accumulate(rec[i])) -    rec[i] = [min(1, reci) for reci in rec[i]] -rec_total = rec[0] -for i in range(1, C): -    for j in range(MAX + 1): -        rec_total[j] = rec_total[j] + rec[i][j] -print((max(rec_total))) +    if s in endset[c]: +        program[c][s] += 1 +        program[c][t] -= 1 +    else: +        program[c][s - 1] += 1 +        program[c][t] -= 1 +for ci in range(ch): +    program[ci] = list(accumulate(program[ci])) +print((max([sum(time_span) for time_span in zip(*program)])))