print(sum([eval(f"-({input().replace(':','*60+').replace(' ',')+(')})+1440")%1440 for _ in[0]*int(input())]))