N = int(input()) s = 0 for i in range(N): tmp = [int(j) for j in input().strip().replace(':', ' ').split(' ')] s += (tmp[2] * 60 + tmp[3] - (tmp[0] * 60 + tmp[1])) % (24 * 60) print('{}'.format(s))