output_description: When the minimum required number of recorders is x, print the value of x.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N C
      s_1 t_1 c_1
      :
      s_N t_N c_N
attempt: import copy
  
  n, C = map(int, input().split())
  stc = [list(map(int, input().split())) for _ in range(n)]
  
  li = [[] for _ in range(C)]
  li2 = []
  
  for s, t, c in stc:
      li[c - 1].append((s, t))
  
  # print(li)
  
  """
  for i in range(C):
      if li[i]:
          li[i].sort()
          flag = False
          count = 0
          for j in range(len(li[i])-1):
              if li[i][j][1] == li[i][j+1][0]:
                  if flag:
                      pass
                  else:
                      flag = True
                      count = j
              else:
                  if flag:
                      flag = False
                      li2.append((li[i][count][0]-0.5, li[i][j][1]))
                  else:
                      li2.append((li[i][j][0]-0.5, li[i][j][1]))
          if flag:
              flag = False
              li2.append((li[i][count][0]-0.5, li[i][-1][1]))
          else:
              li2.append((li[i][-1][0]-0.5, li[i][-1][1]))
  """
  
  for i in range(C):
      if li[i]:
          li[i].sort()
          flag = False
          count = 0
          count2 = 0
          tmp = 0
          li_tmp = []
          while li[i]:
              # print(li[i])
              for j in range(len(li[i]) - 1):
                  if li[i][tmp][1] == li[i][j + 1][0]:
                      if flag:
                          tmp = j + 1
                      else:
                          flag = True
                          count = j
                          tmp = j + 1
                  else:
                      if flag:
                          li_tmp.append((li[i][j + 1][0], li[i][j + 1][1]))
                      else:
                          li2.append((li[i][j][0] - 0.5, li[i][j][1]))
              if flag:
                  flag = False
                  li2.append((li[i][count][0] - 0.5, li[i][tmp][1]))
              else:
                  li2.append((li[i][-1][0] - 0.5, li[i][-1][1]))
              li[i] = copy.copy(li_tmp)
              li_tmp = []
  
  # print(li2)
  
  li2.sort(key=lambda x: x[1])
  ans = 0
  li3 = []
  
  while li2:
      count = 0
      ans += 1
      for i in range(len(li2)):
          if li2[i][0] > count:
              count = li2[i][1]
          else:
              li3.append(li2[i])
      li2 = copy.copy(li3)
      li3 = []
  
  print(ans)
  
problem_description: Statement
  
  Joisino is planning to record N TV programs with recorders.
  
  The TV can receive C channels numbered 1 through C.
  
  The i-th program that she wants to record will be broadcast from time s_i to
  time t_i (including time s_i but not t_i) on Channel c_i.
  
  Here, there will never be more than one program that are broadcast on the same
  channel at the same time.
  
  When the recorder is recording a channel from time S to time T (including time
  S but not T), it cannot record other channels from time S-0.5 to time T
  (including time S-0.5 but not T).
  
  Find the minimum number of recorders required to record the channels so that
  all the N programs are completely recorded.
samples: [{"input": "3 2\n    1 7 2\n    7 8 1\n    8 12 1", "output": "2\n    \n\nTwo recorders can record all the programs, for example, as follows:\n\n  * With the first recorder, record Channel 2 from time 1 to time 7. The first program will be recorded. Note that this recorder will be unable to record other channels from time 0.5 to time 7.\n  * With the second recorder, record Channel 1 from time 7 to time 12. The second and third programs will be recorded. Note that this recorder will be unable to record other channels from time 6.5 to time 12.\n\n* * *"}, {"input": "3 4\n    1 3 2\n    3 4 4\n    1 4 3", "output": "3\n    \n\nThere may be a channel where there is no program to record.\n\n* * *"}, {"input": "9 4\n    56 60 4\n    33 37 2\n    89 90 3\n    32 43 1\n    67 68 3\n    49 51 3\n    31 32 3\n    70 71 1\n    11 12 3", "output": "2"}]