n = int(input()) hour=0 time=0 for i in range(n): data = input().split() H,M = map(int,data[0].split(":")) h,m = map(int,data[1].split(":")) if h >= H: hour = h - H else: hour = 24-H + h if m>=M: min = m-M else: min = 60-M + m hour -= 1 if hour<0: hour += 24 time += hour*60 + min print(time)