
object Main extends App {
  import scala.io.StdIn._
  val (n::c::_) = readLine().split(' ').map(_.toInt).toList
  val programs = (1 to n).toList.map(_ => readLine().split(' ').map(_.toInt)).map(a => Program(a(0), a(1), a(2))).foldLeft(new Array[List[Program]](c + 1).map(_ => Nil:List[Program])){
    (a, p) =>
      a(p.channelNumber) = p::a(p.channelNumber)
      a
  }.map(list => list.sortBy(p => -p.endTime).foldLeft(Nil:List[Program]){
    (l, p) => l match{
      case Nil => p::Nil
      case h::t =>
        if (h.startTime == p.endTime)
          p.merge(h)::t
        else
          p::l
    }
  }).flatMap(l => l).sortBy(_.endTime)
  case class Program(startTime:Int, endTime:Int, channelNumber:Int, programWeight:Int = 1){
    def merge(program: Program):Program = {
      Program(startTime, program.endTime, channelNumber, programWeight + program.programWeight)
    }
  }
  def recorderNeeds(i: Int, programs: List[Main.Program]):Int = {
    var needRecord = i
    def record(prog:List[Program]):List[Program] = {
      prog match{
        case Nil => Nil
        case h::t =>
          needRecord -= h.programWeight
          val (cantRec, canRec) = t.span(p => h.endTime >= p.startTime)
          canRec match{
            case Nil => cantRec
            case _ => cantRec ++ record(canRec)
          }
      }
    }
    var count = 0
    var rest = programs
    while (needRecord > 0){
      rest = record(rest)
      count += 1
    }
    count
  }
  println(recorderNeeds(n, programs.toList))

}
