import datetime n = int(input()) x = 0 for i in range(n): t = input().split() t0 = datetime.datetime.strptime(t[0], '%H:%M') t1 = datetime.datetime.strptime(t[1], '%H:%M') t2 = t1 - t0 h, m = divmod(t2.seconds//60, 60) m += h * 60 x += m print(x)