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

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

tail = {}

head = {}

for i in range(10**5+1):

    tail[i] = []

    head[i] = []

for i in range(N):

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

    if c not in tail[s] and c not in head[t-1]:

        cum[s-1] += 1

        cum[t] -= 1

    elif c not in head[t-1]:

        cum[s] += 1

        cum[t] -= 1

    elif c not in tail[s]:

        cum[s-1] += 1

        cum[t-1] -= 1

    else:

        cum[s] += 1

        cum[t-1] -= 1

    tail[t].append(c)

    head[s-1].append(c)

    

import numpy as np

print((np.cumsum(cum).max()))
N,C = list(map(int,input().split()))

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

st = [[] for _ in range(C)]

for _ in range(N):

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

    st[c-1].append([s,t])

for c in range(C):

    st[c].sort()



st_concat = [[] for _ in range(C)]

for c in range(C):

    if len(st[c]) != 0:

        s0,t0 = st[c].pop()

        while st[c]:

            s,t = st[c].pop()

            if t != s0:

                st_concat[c].append([s0,t0])

                s0,t0 = s,t

            else:

                s0 = s

        st_concat[c].append([s0,t0])



for c in range(C):

    for s,t in st_concat[c]:

        cum[s-1] += 1

        cum[t] -= 1



for i in range(10**5):

    cum[i+1] += cum[i]

print((max(cum)))
N, C = list(map(int, input().split()))
cum = [0] * (10**5 + 1)
tail = {}
head = {}
for i in range(10**5 + 1):
    tail[i] = []
    head[i] = []
for i in range(N):
    s, t, c = list(map(int, input().split()))
    if c not in tail[s] and c not in head[t - 1]:
        cum[s - 1] += 1
        cum[t] -= 1
    elif c not in head[t - 1]:
        cum[s] += 1
        cum[t] -= 1
    elif c not in tail[s]:
        cum[s - 1] += 1
        cum[t - 1] -= 1
    else:
        cum[s] += 1
        cum[t - 1] -= 1
    tail[t].append(c)
    head[s - 1].append(c)
import numpy as np

print((np.cumsum(cum).max()))

N, C = list(map(int, input().split()))
cum = [0] * (10**5 + 1)
st = [[] for _ in range(C)]
for _ in range(N):
    s, t, c = list(map(int, input().split()))
    st[c - 1].append([s, t])
for c in range(C):
    st[c].sort()
st_concat = [[] for _ in range(C)]
for c in range(C):
    if len(st[c]) != 0:
        s0, t0 = st[c].pop()
        while st[c]:
            s, t = st[c].pop()
            if t != s0:
                st_concat[c].append([s0, t0])
                s0, t0 = s, t
            else:
                s0 = s
        st_concat[c].append([s0, t0])
for c in range(C):
    for s, t in st_concat[c]:
        cum[s - 1] += 1
        cum[t] -= 1
for i in range(10**5):
    cum[i + 1] += cum[i]
print((max(cum)))

-tail = {} -head = {} -for i in range(10**5 + 1): -    tail[i] = [] -    head[i] = [] -for i in range(N): +st = [[] for _ in range(C)] +for _ in range(N): -    if c not in tail[s] and c not in head[t - 1]: +    st[c - 1].append([s, t]) +for c in range(C): +    st[c].sort() +st_concat = [[] for _ in range(C)] +for c in range(C): +    if len(st[c]) != 0: +        s0, t0 = st[c].pop() +        while st[c]: +            s, t = st[c].pop() +            if t != s0: +                st_concat[c].append([s0, t0]) +                s0, t0 = s, t +            else: +                s0 = s +        st_concat[c].append([s0, t0]) +for c in range(C): +    for s, t in st_concat[c]: -    elif c not in head[t - 1]: -        cum[s] += 1 -        cum[t] -= 1 -    elif c not in tail[s]: -        cum[s - 1] += 1 -        cum[t - 1] -= 1 -    else: -        cum[s] += 1 -        cum[t - 1] -= 1 -    tail[t].append(c) -    head[s - 1].append(c) -import numpy as np - -print((np.cumsum(cum).max())) +for i in range(10**5): +    cum[i + 1] += cum[i] +print((max(cum)))