n=int(input()) ans=0 for i in range(n): x,y=input().split() a,b=map(int,x.split(":")) c,d=map(int,y.split(":")) if a>c: c+=24 if a==c and b>d: c+=24 ans+=(c*60+d)-(a*60+b) print(ans)