n = int(input()) total = 0 w_all = 0 s_all = 0 for i in range(n): s, w = input().split() s_h, s_m= map(int, s.split(':')) w_h, w_m= map(int, w.split(':')) if len(str(s_h)) == 2 and len(str(w_h)) <= 1: w_all = int(w_h) * 60 + 1440 + int(w_m) s_all = int(s_h) * 60 + int(s_m) elif s_h == 0 and w_h == 0 and s_m <= w_m: w_all = w_m - s_m elif s_h == 0 and w_h == 0 and s_m >= w_m: w_all = 1440 - s_m elif len(str(s_h)) <= 1 and len(str(w_h)) <= 1: w_all = int(w_h) * 60 + 1440 + int(w_m) s_all = int(s_h) * 60 + 1440 + int(s_m) total += w_all - s_all print(total)