object Main extends App {
  override def main(args: Array[String]): Unit = {
    import scala.io.{StdIn => in}
    Iterator
      .continually(in.readInt())
      .takeWhile(_ != 0)
      .map(n =>
        for (x <- 1 to n) yield in.readLine()
      ).map(solve).foreach(println)
  }

  def solve(input: Seq[String]): Int = {
    def toMinutes(input: String): Int = input.substring(6, 8).toInt * 60 + input.substring(9, 11).toInt
    def getDistance(currentNext: (String, String)): Int = toMinutes(currentNext._2) - toMinutes(currentNext._1)

    val sorted = input.sorted
    val range = sorted.zip(sorted.drop(1)).map(getDistance(_))
    val scanned = sorted.scanLeft(Set[String]()){(set,string) => if (string(12) == 'I') set + string.substring(14) else set - string.substring(14)}
    val result = range.zip(scanned.drop(1)).filter(_._2.contains("000")).foldLeft(Map[String, Int]()) {
      (z, data) => data._2.filter(_ != "000").foldLeft(z)((zz, nn) => zz + (nn -> (zz.getOrElse(nn, 0) + data._1)))
    }
    result.maxBy(z => z._2)._2
  }
}