N = int(input())

ans = 0

for _ in range(N):
	HM, hm = input().split()
	H, M = map(int, HM.split(':'))
	h, m = map(int, hm.split(':'))

	beg = H * 60 + M
	end = h * 60 + m

	if beg > end:
		end += 60 * 24

	ans += end - beg	

print(ans)