# -*- coding: utf-8 -*- N = int(input()) total = 0 for i in range(N): temp = list(input().split()) H,M = map(int, temp[0].split(':')) h,m = map(int, temp[1].split(':')) h_diff = 0 m_diff = 0 if H>h: h += 24 h_diff = h - H else: h_diff = h - H if M>m: m += 60 m_diff = m - M h_diff -= 1 else: m_diff = m - M if h_diff < 0: h_diff += 24 total += h_diff*60 + m_diff print(total)