n = gets.to_i ans = 0 n.times{ s,t,h,m = gets.split.map{|t|t.split(?:).map(&:to_i)}.flatten tmp = (h-s)*60 + m-t ans += tmp%(24*60) } p ans