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 heapq
  
  N, C, *STC = [int(_) for _ in open(0).read().split()]
  STC = [(s, t, c) for s, t, c in zip(STC[::3], STC[1::3], STC[2::3])]
  STC.sort()
  # もしcを映しているテレビがあるならこれにしてしまうのが最適
  # cを映しているテレビがないならすでに終わっているテレビのどれかを選ぶ
  # どのテレビもすでに映しているなら新しいテレビを追加する
  
  
  class SegmentTree:
      def __init__(self, array, f, ti):
          """
          Parameters
          ----------
          array : list
              to construct segment tree from
          f : func
              binary operation of the monoid
          ti :
              identity element of the monoid
          """
          self.f = f
          self.ti = ti
          self.n = n = 2 ** (len(array).bit_length())
          self.dat = dat = [ti] * n + array + [ti] * (n - len(array))
          for i in range(n - 1, 0, -1):  # build
              dat[i] = f(dat[i << 1], dat[i << 1 | 1])
  
      def update(self, p, v):  # set value at position p (0-indexed)
          f, n, dat = self.f, self.n, self.dat
          p += n
          dat[p] = v
          while p > 1:
              p >>= 1
              dat[p] = f(dat[p << 1], dat[p << 1 | 1])
  
      def operate_right(self, p, v):  # apply operator from the right side
          f, n, dat = self.f, self.n, self.dat
          p += n
          dat[p] = f(dat[p], v)
          while p > 1:
              p >>= 1
              dat[p] = f(dat[p << 1], dat[p << 1 | 1])
  
      def operate_left(self, p, v):  # apply operator from the left side
          f, n, dat = self.f, self.n, self.dat
          p += n
          dat[p] = f(v, dat[p])
          while p > 1:
              p >>= 1
              dat[p] = f(dat[p << 1], dat[p << 1 | 1])
  
      def query(self, l, r):  # result on interval [l, r) (0-indexed)
          f, ti, n, dat = self.f, self.ti, self.n, self.dat
          vl = vr = ti
          l += n
          r += n
          while l < r:
              if l & 1:
                  vl = f(vl, dat[l])
                  l += 1
              if r & 1:
                  r -= 1
                  vr = f(dat[r], vr)
              l >>= 1
              r >>= 1
          return f(vl, vr)
  
  
  ti = (10**10, -(10**10))
  st = SegmentTree([(10**10, i) for i in range(C + 1)], min, ti)
  ans = 0
  for s, t, c in STC:
      if st.query(c, c + 1)[0] == 10**10:
          t2, c2 = st.query(1, C + 1)
          if t2 < s:
              st.update(c2, (10**10, c2))
          else:
              ans += 1
      st.update(c, (t, c))
  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"}]