n = int(input()) ans = 0 for _ in range(n): hw0, hw1 = input().split() h0, w0 = hw0.split(":") h1, w1 = hw1.split(":") h0 ,h1, w0, w1 = int(h0), int(h1), int(w0), int(w1) if h1 != h0: ans += (h1 - h0) % 24 * 60 else: if w0 > w1: ans += 1440 ans += w1 - w0 print(ans)