s=0 N=int(input()) for i in range(0, N): HhMm=input().split() H,M=map(int, HhMm[0].split(':')) h,m=map(int, HhMm[1].split(':')) t=(h-H)%24*60 + m-M s+=t if t>0 else t+24*60 print(s)