N = int(input()) ans = 0 for _ in range(N): sleep, awake = map(str,input().split()) H1,H2 = map(int,sleep.split(":")) h1,h2 = map(int,awake.split(":")) if H1 > h1 or (H1 == 0 and h1 == 0 and H2 > h2): h1 += 24 ans += (h1-H1)*60 + h2-H2 print(ans)