import java.util.*

fun main(args:Array<String>):Unit {
    while(true){
        val (n, p, q) = readLine()!!.trim().split(' ').map(String::toInt)
        if (n == 0 && p == 0 && q == 0) return
        val stack:Stack<Pair<Int, Boolean>> = Stack()
        repeat(n) {
            stack.push(Pair(p, false))
            stack.push(Pair(q, true))
        }
        repeat(n){
            readLine()
            readLine()!!.trim().split(' ').map(String::toInt).forEachIndexed { index, s ->
                stack.push(Pair(s, index % 2 == 0))
            }
        }
        val sorted = stack.sortedWith(compareBy(Pair<Int, Boolean>::first, Pair<Int, Boolean>::second))
        var max = 0
        var count = 0
        var startTime = 0
        for ((time, isStart) in sorted){
            if (!isStart){
                if (count == 0) startTime = time
                ++count
            }else{
                --count
                if (count == 0){
                    if (max < time - startTime)
                        max = time - startTime
                }
            }
        }
        println((max / 100) * 60 + max % 100)
    }
}
