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:
        h1 += 24
    if h2 < H2:
        ans += (h1-H1-1)*60 + 60+(h2-H2)
    else:
        ans += (h1-H1)*60 + h2-H2
print(ans)