n = int(input()) res = 0 for _ in range(n): p,q = input().split() a,b = map(int, p.split(':')) c,d = map(int, q.split(':')) c += 24 mn = c * 60 + d - a * 60 - b mn %= 24 * 60 res += mn print(res)