
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)).sortBy(_(1))
  def recorderNeeds(programNumber:Int, programsList:List[Array[Int]]):Int = {
    if (programNumber <= 0) 0
    else {
      var needRecord = programNumber
      def addRecorder(proList: List[Array[Int]], prev:Int = 0, prevChannel:Int = 0):List[Array[Int]] = {
        proList match{
          case Nil => Nil
          case list =>
            val (cantRec, canRec) = list.span(a => (a(2) == prevChannel && a(0) < prev) ||a(0) <= prev)
            canRec match{
              case Nil => cantRec
              case h::t =>
                needRecord -= 1
                cantRec ++ addRecorder(t, h(1), h(2))
            }
        }
      }
      val rest = addRecorder(programsList)
      recorderNeeds(needRecord, rest) + 1
    }
  }
  println(recorderNeeds(n, programs))

}
