n=int(input()) ans=0 for _ in range(n): h1,m1,h2,m2=input().replace('.',' ').split() a=h2*60+m2-h1*60-m1 if a<0: a+=3600 ans+=a print(ans)