def to_min(hhmm: str) -> int: h, m = map(int, hhmm.split(':')) return h * 60 + m N = int(input()) ans = 0 for i in range(N): b, w = map(to_min, input().split(' ')) if b > w: b -= 24 * 60 ans += w - b print(ans)