# -*- coding:utf-8 -*- def hm_to_m(hm): return hm[0] * 60 + hm[1] if __name__ == '__main__': n = int(input()) cnt = 0 for i in range(n): hm1, hm2 = (tuple(map(int, hm.split(":"))) for hm in input().split()) cnt += (hm_to_m(hm2) - hm_to_m(hm1)) % (60 * 24) print(cnt)