def line(a)
  (a / 100) * 60 + a % 100
end
while l = gets
  n, p, q = l.split.map(&:to_i)
  p = line(p)
  q = line(q)
  break if n == 0
  m = Array.new(n){ Array.new(q-p) }
  n.times do |j|
    k = gets.to_i
    a = gets.split.map(&:to_i)
    k.times do |i| 
      (line(a[2*i])-p...line(a[2*i+1])-p).each do |r|
        m[j][r] = true
      end
    end
  end
  ret = 0
  cnt = 0
  flag = false
  m.transpose.each do |item|
    if item.any?{ |t| !t }
      cnt += 1
      if !flag
        flag = true
      end
    elsif item.all?{ |t| t }
      if flag
        ret = cnt if cnt > ret
      end
      cnt = 0
      flag = false
    end
  end
  ret = cnt if cnt > ret
  p ret
end