#!/usr/bin/env python3

#ABC80 D



import sys

import math

import bisect

sys.setrecursionlimit(1000000000)

from heapq import heappush, heappop,heappushpop

from collections import defaultdict

from itertools import accumulate

from collections import Counter

from collections import deque

from operator import itemgetter

from itertools import permutations

mod = 10**9 + 7

inf = float('inf')

def I(): return int(sys.stdin.readline())

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





n,C = LI()

stc = [LI() for _ in range(n)]

L = []

for i in range(C):

    lst = []

    for j in range(n):

        s,t,c = stc[j]

        if i+1 == c:

            lst.append([s,t])

    lst.sort(key = itemgetter(0))

    lst2 = []

    j = 0

    while j < len(lst):

        if j < len(lst)-1:

            if lst[j][1] == lst[j+1][0]:

                lst2.append((lst[j][0],lst[j+1][1]))

                j += 2

                continue



        lst2.append(tuple(lst[j]))

        j += 1

    L.append(lst2)

x = [[0]*100002 for _ in range(C)]

for i in range(C):

    for j,k in L[i]:

        x[i][j] += 1

        x[i][k+1] -= 1

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

ans = 0

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

    s = 0

    for j in range(C):

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

            s += 1

    ans = max(ans,s)

print(ans)

#!/usr/bin/env python3

#ABC80 D



import sys

import math

import bisect

sys.setrecursionlimit(1000000000)

from heapq import heappush, heappop,heappushpop

from collections import defaultdict

from itertools import accumulate

from collections import Counter

from collections import deque

from operator import itemgetter

from itertools import permutations

mod = 10**9 + 7

inf = float('inf')

def I(): return int(sys.stdin.readline())

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



n,C = LI()

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

ans = 0

lst = [0]*(10**5+2)

for _ in range(n):

    s,t,c = LI()

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

for i in range(C):

    if len(cha[i]) == 0:

        continue

    cha[i].sort(key = itemgetter(0))

    s,t = cha[i][0]

    tmp = []

    for j in range(1,len(cha[i])):

        if t == cha[i][j][0]:

            t = cha[i][j][1]

        else:

            tmp.append([s,t])

            s,t = cha[i][j]

    tmp.append([s,t])

    for i,j in tmp:

        lst[i] += 1

        lst[j+1] -= 1

lst = list(accumulate(lst))

print((max(lst)))

#!/usr/bin/env python3
# ABC80 D
import sys
import math
import bisect

sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop, heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations

mod = 10**9 + 7
inf = float("inf")


def I():
    return int(sys.stdin.readline())


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


n, C = LI()
stc = [LI() for _ in range(n)]
L = []
for i in range(C):
    lst = []
    for j in range(n):
        s, t, c = stc[j]
        if i + 1 == c:
            lst.append([s, t])
    lst.sort(key=itemgetter(0))
    lst2 = []
    j = 0
    while j < len(lst):
        if j < len(lst) - 1:
            if lst[j][1] == lst[j + 1][0]:
                lst2.append((lst[j][0], lst[j + 1][1]))
                j += 2
                continue
        lst2.append(tuple(lst[j]))
        j += 1
    L.append(lst2)
x = [[0] * 100002 for _ in range(C)]
for i in range(C):
    for j, k in L[i]:
        x[i][j] += 1
        x[i][k + 1] -= 1
    x[i] = list(accumulate(x[i]))
ans = 0
for i in range(1, 10**5 + 1):
    s = 0
    for j in range(C):
        if x[j][i] == 1:
            s += 1
    ans = max(ans, s)
print(ans)

#!/usr/bin/env python3
# ABC80 D
import sys
import math
import bisect

sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop, heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations

mod = 10**9 + 7
inf = float("inf")


def I():
    return int(sys.stdin.readline())


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


n, C = LI()
cha = [[] for _ in range(C)]
ans = 0
lst = [0] * (10**5 + 2)
for _ in range(n):
    s, t, c = LI()
    cha[c - 1].append([s, t])
for i in range(C):
    if len(cha[i]) == 0:
        continue
    cha[i].sort(key=itemgetter(0))
    s, t = cha[i][0]
    tmp = []
    for j in range(1, len(cha[i])):
        if t == cha[i][j][0]:
            t = cha[i][j][1]
        else:
            tmp.append([s, t])
            s, t = cha[i][j]
    tmp.append([s, t])
    for i, j in tmp:
        lst[i] += 1
        lst[j + 1] -= 1
lst = list(accumulate(lst))
print((max(lst)))

-stc = [LI() for _ in range(n)] -L = [] +cha = [[] for _ in range(C)] +ans = 0 +lst = [0] * (10**5 + 2) +for _ in range(n): +    s, t, c = LI() +    cha[c - 1].append([s, t]) -    lst = [] -    for j in range(n): -        s, t, c = stc[j] -        if i + 1 == c: -            lst.append([s, t]) -    lst.sort(key=itemgetter(0)) -    lst2 = [] -    j = 0 -    while j < len(lst): -        if j < len(lst) - 1: -            if lst[j][1] == lst[j + 1][0]: -                lst2.append((lst[j][0], lst[j + 1][1])) -                j += 2 -                continue -        lst2.append(tuple(lst[j])) -        j += 1 -    L.append(lst2) -x = [[0] * 100002 for _ in range(C)] -for i in range(C): -    for j, k in L[i]: -        x[i][j] += 1 -        x[i][k + 1] -= 1 -    x[i] = list(accumulate(x[i])) -ans = 0 -for i in range(1, 10**5 + 1): -    s = 0 -    for j in range(C): -        if x[j][i] == 1: -            s += 1 -    ans = max(ans, s) -print(ans) +    if len(cha[i]) == 0: +        continue +    cha[i].sort(key=itemgetter(0)) +    s, t = cha[i][0] +    tmp = [] +    for j in range(1, len(cha[i])): +        if t == cha[i][j][0]: +            t = cha[i][j][1] +        else: +            tmp.append([s, t]) +            s, t = cha[i][j] +    tmp.append([s, t]) +    for i, j in tmp: +        lst[i] += 1 +        lst[j + 1] -= 1 +lst = list(accumulate(lst)) +print((max(lst)))