n = int(input()) ans = 0 for i in range(n): a,b = input().split() H,M = map(int,a.split(":")) h,m = map(int,b.split(":")) a = H*60+M b = h*60+m if a <= b: ans += b-a else: ans += b+60*24-a print(ans)