n = int(input()) ret = 0 for _ in range(n): line = list(input().split()) h1,m1 = map(int, line[0].split(':')) h2,m2 = map(int, line[1].split(':')) s = h2*60+m2 - h1*60-m1 if s<0: s += 24*60 ret += s print(ret)