n=input() l=lambda x:x[0]*60+x[1] print sum((i[1]-i[0]+1440)%1440 for i in[[l(map(int,i.split(":")))for i in raw_input().split()]for i in[0]*n])