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 hM: sleep+=(m-M) else: sleep+=(23*60+(60-(M-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