n=STDIN.gets.to_i ans=0 n.times do |i| a,b=STDIN.gets.split(" ") hh,mm=a.split(":") h,m=b.split(":") p1=hh.to_i*60+mm.to_i p2=h.to_i*60+m.to_i+60*24 ans+=(p2-p1)%(60*24) end puts ans