N = int(input()) sum = 0 for _ in range(N): st, ed = map(str, input().split(' ')) stH, stM = map(int, st.split(':')) edH, edM = map(int, ed.split(':')) sum += ((edH + 23 - stH) if stH > edH else edH - stH - 1) * 60 sum += edM - stM if stH == edH else 60 - stM + edM print(sum)