# import sys; input = sys.stdin.buffer.readline # sys.setrecursionlimit(10**7) from collections import defaultdict con = 10 ** 9 + 7; INF = float("inf") def getlist(): return list(map(int, input().split())) #処理内容 def main(): N = int(input()) ans = 0 for i in range(N): A, B = list(input().split()) H1, M1 = list(A.split(":")) h1, m1 = list(B.split(":")) H1 = int(H1); M1 = int(M1); h1 = int(h1); m1 = int(m1) dif = (60 * h1 + m1 - 60 * H1 - M1) % 1440 ans += dif print(ans) if __name__ == '__main__': main()