s=0
gets.to_i.times{h,m,a,b=gets.split(/[ :]/).map &:to_i
s+=((a-h)*60+b-m)%1440}
p s