hs=ms=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(':')) hs+=(h-H)%24 ms+=m-M print(hs*60+ms)