N = int(input()) def f(s: str) -> int: h, m = map(int, s.split(':')) return h * 60 + m ans = 0 for _ in range(N): s, t = input().split() a = f(s) b = f(t) if a < b: ans += b - a else: ans += (24 * 60 - a) + b print(ans)