N = int(input()) records = [input().split() for _ in range(N)] ans = 0 for a, b in records: h_st, m_st = map(int, a.split(":")) h_end, m_end = map(int, b.split(":")) if h_st > h_end: ans += (23 - h_st + h_end) * 60 + (60 - m_st + m_end) else: ans += (h_end - h_st) * 60 + (m_end - m_st) print(ans)