N = int(input()) t = 0 for _ in range(N): a, b = input().split() hs, ms = map(int, a.split(':')) he, me = map(int, b.split(':')) s = hs*60 + ms e = he*60 + me t += e - s + [0, 1440][ s > e] print(t)