def timecalc(h, m): return 60*h+m N = int(raw_input()) sum = 0 for i in range(0, N): inpt = raw_input().split() sleep = map(int, inpt[0].split(':')) awake = map(int, inpt[1].split(':')) sm = timecalc(sleep[0], sleep[1]) wm = timecalc(awake[0], awake[1]) if wm < sm: sum += (1440-sm) + wm else: sum += wm-sm print sum