c,w=0,1440 for _ in'1'*int(input()): x,y,h,m=map(int,input().replace(':',' ').split()) c+=((h-x)*60+m-y+w)%w print(c)