import java.io.{BufferedReader, InputStream, InputStreamReader}
import java.util.{Comparator, StringTokenizer}

import scala.collection.mutable
import scala.util.Sorting
import math.{abs, max, min}
import scala.collection.mutable.{ArrayBuffer, ListBuffer}

object Main {
  val MOD = 1000000007
  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N, C = sc.nextInt()
    type Schedule = (Int, Int)
    val schedules = Array.fill[ArrayBuffer[Schedule]](C)(ArrayBuffer())
    (0 until N) foreach { _ =>
      val s, t = sc.nextInt()
      val c = sc.nextInt() - 1
      schedules(c) += ((s, t))
    }

    val d = Array.ofDim[Int](200002)
    (0 until C) foreach { c =>
      iterateMergedSchedule(c) { case (s, t) =>
        d(s * 2 - 1) += 1
        d(t * 2) -= 1
      }
    }

    def iterateMergedSchedule(c: Int)(f: Schedule => Unit): Unit = {
      val sorted = schedules(c).sortBy(_._1)
      val n = sorted.length
      def step(i: Int, prev: Schedule): Unit = {
        if (i == n) f(prev)
        else {
          val cur = sorted(i)
          if (prev._2 == cur._1) step(i + 1, (prev._1, cur._2)) // merge
          else {
            f(prev)
            step(i + 1, cur)
          }
        }
      }

      if (sorted.nonEmpty) step(1, sorted.head)
    }

    (0 until d.length - 1) foreach { i =>
      d(i + 1) += d(i)
    }

    val ans = d.max
    println(ans)
  }


  def main(args: Array[String]): Unit = {
    solve()
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = null

    def next: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next.toInt
    def nextLong(): Long = next.toLong
    def nextChar(): Char = next.charAt(0)
  }

}
