ary = [] sum = 0 for i in range(int(input())): ary.append([]) ary[i] = input().split() tmp0 = list(map(int, ary[i][0].split(':'))) tmp1 = list(map(int, ary[i][1].split(':'))) if(tmp0[0] > tmp1[0]): sum += (24 - tmp0[0] - 1) * 60 + (60 - tmp0[1]) sum += tmp1[0] * 60 + tmp1[1] else: sum += (tmp1[0] * 60 + tmp1[1]) - (tmp0[0] * 60 + tmp0[1]) if((tmp1[0] * 60 + tmp1[1]) - (tmp0[0] * 60 + tmp0[1])== -1): sum += 24 * 60 print(sum)