import java.util.*
import java.util.Collections.sort

fun main(args: Array<String>) {
    val (N, C) = readLine()!!.split(" ").map{it.toInt()}
    val P = ArrayList<Triple<Int, Int, Int>>()

    for (i in 1..N) {
        val (s, t, c) = readLine()!!.split(" ").map { it.toInt() }
        P.add(Triple(s, t, c))
    }
    sort(P) { a, b -> a.first - b.first }

    val Q = ArrayList<Pair<Int, Int>>()

    for(p in P) {
        val k = Q.indexOfFirst { it.first == p.first && it.second == p.third }
        val l = Q.indexOfFirst { it.first < p.first }
        val r = Pair(p.second, p.third)

        when {
            k >= 0 -> Q[k] = r
            l >= 0 -> Q[l] = r
            else -> Q.add(r)
        }
    }

    println(Q.size)
}
