import sys

from itertools import accumulate



# functions used

r = lambda: sys.stdin.readline().strip() #single: int(r()), line: map(int, r().split())

R = lambda: list(map(int, r().split())) # line: R(), lines: [R() for _ in range(n)]

Rmap = lambda: list(map(int, r().split()))

# set inputs

N, C = R()

STC = [R() for _ in range(N)]

#  0.5sec as one unit

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



for s, t, c in STC:

    c -= 1

    # if we can record the programms continuously (ver1)

    if tbl[c][2*s] != 0:

        tbl[c][2*s] += 1

        tbl[c][2*t] -= 1

    # if we can record the programms continuously (ver2)

    elif tbl[c][2*t-1] != 0:

        tbl[c][2*t-1] -= 1

        tbl[c][2*s-1] += 1

    # else:

    else:

        tbl[c][2*s-1] = 1

        tbl[c][2*t] = -1



tbl2 = [list(accumulate(a)) for a in tbl]



# ans = max([sum(x) for x in zip(*tbl2)])

# print(ans)



res = 0

for i in range(200002):

    cc = 0

    for j in range(C):

        if tbl2[j][i] == 1:

            cc += 1

    res = max(res, cc)

print(res)

import sys

from itertools import accumulate



# functions used

r = lambda: sys.stdin.readline().strip() #single: int(r()), line: map(int, r().split())

R = lambda: list(map(int, r().split())) # line: R(), lines: [R() for _ in range(n)]

Rmap = lambda: list(map(int, r().split()))

# set inputs

N, C = R()

STC = [R() for _ in range(N)]

#  0.5sec as one unit

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



for s, t, c in STC:

    c -= 1

    # if we can record the programms continuously (ver1)

    if tbl[c][2*s] != 0:

        tbl[c][2*s] += 1

        tbl[c][2*t] -= 1

    # if we can record the programms continuously (ver2)

    elif tbl[c][2*t-1] != 0:

        tbl[c][2*t-1] -= 1

        tbl[c][2*s-1] += 1

    # else:

    else:

        tbl[c][2*s-1] = 1

        tbl[c][2*t] = -1



tbl2 = [list(accumulate(a)) for a in tbl]

for i in range(200002):

     for j in range(C):

         if tbl2[j][i]==2:

          	tbl2[j][i]=1



ans = max([sum(x) for x in zip(*tbl2)])

print(ans)



# tmp = [sum(x) for x in zip(*tbl2)]



# res = 0

# for i in range(200002):

#     cc = 0

#     for j in range(C):

#         if tbl2[j][i]:

#             cc += 1

#     res = max(res, cc)

# print(res)

import sys
from itertools import accumulate

# functions used
r = (
    lambda: sys.stdin.readline().strip()
)  # single: int(r()), line: map(int, r().split())
R = lambda: list(map(int, r().split()))  # line: R(), lines: [R() for _ in range(n)]
Rmap = lambda: list(map(int, r().split()))
# set inputs
N, C = R()
STC = [R() for _ in range(N)]
#  0.5sec as one unit
tbl = [[0] * (2 * (10**5) + 5) for _ in range(C)]
for s, t, c in STC:
    c -= 1
    # if we can record the programms continuously (ver1)
    if tbl[c][2 * s] != 0:
        tbl[c][2 * s] += 1
        tbl[c][2 * t] -= 1
    # if we can record the programms continuously (ver2)
    elif tbl[c][2 * t - 1] != 0:
        tbl[c][2 * t - 1] -= 1
        tbl[c][2 * s - 1] += 1
    # else:
    else:
        tbl[c][2 * s - 1] = 1
        tbl[c][2 * t] = -1
tbl2 = [list(accumulate(a)) for a in tbl]
# ans = max([sum(x) for x in zip(*tbl2)])
# print(ans)
res = 0
for i in range(200002):
    cc = 0
    for j in range(C):
        if tbl2[j][i] == 1:
            cc += 1
    res = max(res, cc)
print(res)

import sys
from itertools import accumulate

# functions used
r = (
    lambda: sys.stdin.readline().strip()
)  # single: int(r()), line: map(int, r().split())
R = lambda: list(map(int, r().split()))  # line: R(), lines: [R() for _ in range(n)]
Rmap = lambda: list(map(int, r().split()))
# set inputs
N, C = R()
STC = [R() for _ in range(N)]
#  0.5sec as one unit
tbl = [[0] * (2 * (10**5) + 5) for _ in range(C)]
for s, t, c in STC:
    c -= 1
    # if we can record the programms continuously (ver1)
    if tbl[c][2 * s] != 0:
        tbl[c][2 * s] += 1
        tbl[c][2 * t] -= 1
    # if we can record the programms continuously (ver2)
    elif tbl[c][2 * t - 1] != 0:
        tbl[c][2 * t - 1] -= 1
        tbl[c][2 * s - 1] += 1
    # else:
    else:
        tbl[c][2 * s - 1] = 1
        tbl[c][2 * t] = -1
tbl2 = [list(accumulate(a)) for a in tbl]
for i in range(200002):
    for j in range(C):
        if tbl2[j][i] == 2:
            tbl2[j][i] = 1
ans = max([sum(x) for x in zip(*tbl2)])
print(ans)
# tmp = [sum(x) for x in zip(*tbl2)]
# res = 0
# for i in range(200002):
#     cc = 0
#     for j in range(C):
#         if tbl2[j][i]:
#             cc += 1
#     res = max(res, cc)
# print(res)

-# ans = max([sum(x) for x in zip(*tbl2)]) -# print(ans) -res = 0 -    cc = 0 -        if tbl2[j][i] == 1: -            cc += 1 -    res = max(res, cc) -print(res) +        if tbl2[j][i] == 2: +            tbl2[j][i] = 1 +ans = max([sum(x) for x in zip(*tbl2)]) +print(ans) +# tmp = [sum(x) for x in zip(*tbl2)] +# res = 0 +# for i in range(200002): +#     cc = 0 +#     for j in range(C): +#         if tbl2[j][i]: +#             cc += 1 +#     res = max(res, cc) +# print(res)