### subroutines

def hm2m(hm)
  (hm / 100) * 60 + (hm % 100)
end

### main

loop do
  n, hm0, hm1 = gets.strip.split(' ').map(&:to_i)
  break if (n | hm0 | hm1) == 0

  cmks = []
  cms = []

  n.times do
    k = gets.strip.to_i
    cmks << k

    tmps = gets.strip.split(' ').map(&:to_i)
    cms << (0...k).map{|i| [tmps[2 * i], tmps[2 * i + 1]]}.sort
  end

  its = [[hm0, hm1]]

  for i in (0...n)
    break if its.empty?

    pits = its
    its = []

    pit = pits.shift

    for j in (0...cmks[i])
      cm0, cm1 = cms[i][j]

      while pit[1] <= cm0
        pit = pits.shift
        break if pit.nil?
      end
      next if pit.nil?

      p0 = [cm0, pit[0]].max
      p1 = [cm1, pit[1]].min
      its << [p0, p1] if p0 < p1
    end
  end

  pgs = [hm0] + its.flatten + [hm1]
  max_min = 0

  while ! pgs.empty?
    m0 = hm2m(pgs.shift)
    m1 = hm2m(pgs.shift)

    min = m1 - m0
    max_min = min if max_min < min
  end

  puts min
end