t = gets.to_i; ans=0; t.times { s, t = gets.split; a, b = s.split(":").map(&:to_i); c, d = t.split(":").map(&:to_i); # p [a, b, c, d]; l = a * 60 + b; r = c * 60 + d; if l > r then r += 60 * 24; end ans += r - l; } puts ans