def f(s):h,m=map(int,s.split(":"));return 60*h+m a=0 for i in[0]*input():p,q=map(f,raw_input().split());a+=[q-p,1440-p+q][q