N = gets.to_i
p N.times.map{
  hm1, hm2 = gets.split.map{|s|
    h, m = s.split(?:).map(&:to_i)
    h* 60 + m
  }
  (hm2 - hm1) % 1440
}.sum