N = int(input()) total = 0 for _ in range(N): HMhm = input().split() H, M = HMhm[0].split(':') h, m = HMhm[1].split(':') h1 = int(H) * 60 + int(M) h2 = int(h) * 60 + int(m) if h1 > h2: h1 = 1440 - h1 total += h1 + h2 else: total += h2 - h1 print(total)