n = int(input()) ans = 0 for i in range(n): s, e = input().split() hs, ms = map(int, s.split(':')) ms += hs * 60 he, me = map(int, e.split(':')) me += he * 60 if me <= ms: me += 60 * 24 ans += me - ms print(ans)