def getSleepTime(s): start, end = s.split(" ") start = list(map(int, start.split(":"))) end = list(map(int, end.split(":"))) if start[0]*60 + start[1] > end[0]*60 + end[1]: #分でも比較 end[0] += 24 s_min = start[0]*60 + start[1] e_min = end[0]*60 + end[1] return e_min - s_min N = int(input()) print(sum([getSleepTime(input()) for i in range(N)]))