N=int(input()) sleep=0 for _ in range(N): IN,OUT=input().split() H,M=IN.split(":") h,m=OUT.split(":") H,M,h,m=int(H),int(M),int(h),int(m) if h<=H and H<=23: sleep+=(((23-H)*60+(60-M))+h*60+m) elif 0<=H and H<=h: if m>M: sleep+=((h-H)*60+(m-M)) elif m==0 and M!=0: sleep+=((h-H-1)*60+(60-M)) elif m