N = int(input()) ans = 0 for i in range(N): neta, okita = input().split() j = neta.index(":") H = int(neta[:j]) M = int(neta[j + 1:]) j = okita.index(":") h = int(okita[:j]) m = int(okita[j + 1:]) if H > h: H -= 24 if M > m: M -= 60 H += 1 ans += (h - H) * 60 + (m - M) print(ans)