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



r = [[0 for i in range(c)] for j in range(100000)]  # テレビ局の番組表

for dummy in range(n):  # 入力

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

    for j in range(s - 1, t):

        r[j][c - 1] = 1  # 放送中なら1



ans = 0

for i in range(100000):

    if sum(r[i]) > ans:

        ans = sum(r[i])  # 同時に放送されている番組の最大数



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

r = [[0] * C for _ in range(10 ** 5)]

for _ in range(N):

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

    for i in range(s - 1, t):

        r[i][c - 1] = 1

ans = 0

for t in r:

    sum_t = sum(t)

    if sum_t > ans:

        ans = sum_t



print(ans)
n, c = list(map(int, input().split()))
r = [[0 for i in range(c)] for j in range(100000)]  # テレビ局の番組表
for dummy in range(n):  # 入力
    s, t, c = list(map(int, input().split()))
    for j in range(s - 1, t):
        r[j][c - 1] = 1  # 放送中なら1
ans = 0
for i in range(100000):
    if sum(r[i]) > ans:
        ans = sum(r[i])  # 同時に放送されている番組の最大数
print(ans)

N, C = list(map(int, input().split()))
r = [[0] * C for _ in range(10**5)]
for _ in range(N):
    s, t, c = list(map(int, input().split()))
    for i in range(s - 1, t):
        r[i][c - 1] = 1
ans = 0
for t in r:
    sum_t = sum(t)
    if sum_t > ans:
        ans = sum_t
print(ans)

-n, c = list(map(int, input().split())) -r = [[0 for i in range(c)] for j in range(100000)]  # テレビ局の番組表 -for dummy in range(n):  # 入力 +N, C = list(map(int, input().split())) +r = [[0] * C for _ in range(10**5)] +for _ in range(N): -    for j in range(s - 1, t): -        r[j][c - 1] = 1  # 放送中なら1 +    for i in range(s - 1, t): +        r[i][c - 1] = 1 -for i in range(100000): -    if sum(r[i]) > ans: -        ans = sum(r[i])  # 同時に放送されている番組の最大数 +for t in r: +    sum_t = sum(t) +    if sum_t > ans: +        ans = sum_t