N=int(input()) T=[[i for i in input (). split()] for i in range (N)] H=[[0]*4]*N #H=[0]*N #M=[0]*N #=[0]*N #M=[0]*N S=0 for i in range (N): # print (T[i][0]) H[i][0],H[i][1]=(T[i][0]. split (":")) H[i][2],H[i][3]=(T[i][1]. split (":")) for j in range(4): H[i][j]=int(H[i][j]) M=H[i][3]-H[i][1] # if M<0: # M+=60 # H[i][0]-=1 Hh=H[i][2]-H[i][0] if Hh<0: Hh+=24 Hh*=60 Hh+=M S+=Hh # print (S) print (S)