N = int(input()) t = 0 for _ in range(N): HM, hm = input().split() H, M = map(int, HM.split(':')) h, m = map(int, hm.split(':')) s = H * 60 + M w = h * 60 + m if w < s: w += 24 * 60 t += w - s print(t)