n = int(input()) a,b = 0,0 for i in range(n): H,M,h,m = map(int,input().replace(":"," ").split()) a += ((h*60+m)-(H*60+M)+1440)%1440 print(a)