object Main extends App {
  import scala.io.StdIn._


  val n = readInt
  val persons = Array.tabulate(n){_ ⇒
    val Array(ash, asm, aeh, aem, bsh, bsm, beh, bem, csh, csm, ceh, cem) = readLine.trim.split(' ').map(_.toInt)
    Person(IntRange(ash * 60 + asm, aeh * 60 + aem), IntRange(bsh * 60 + bsm, beh * 60 + bem), IntRange(csh * 60 + csm, ceh * 60 + cem))
  }
  println(
    (0 until n).map(a ⇒ (0 until n).map(b ⇒ (0 until n).map(c ⇒ persons.count(_.canEatAll(persons(a).breakFirst.from, persons(b).lunch.from, persons(c).dinner.from))).max).max).max
  )
  case class Person(breakFirst: IntRange, lunch: IntRange, dinner: IntRange){
    def canEatAll(breakFirstTime: Int, lunchTime: Int, dinnerTime: Int): Boolean = breakFirst.contains(breakFirstTime) && lunch.contains(lunchTime) && dinner.contains(dinnerTime)
  }
  case class IntRange(from: Int, to: Int) {
    def contains(value: Int): Boolean = from <= value && value <= to
  }
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline
    def let[A](func: T ⇒ A): A = func(value)
    @inline
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
  }
}
