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