N=int(input()) ANS=0 for i in range(N): x,y=input().split() h,m=x.split(":") h2,m2=y.split(":") #print(h,m,h2,m2) h=int(h) m=int(m) h2=int(h2) m2=int(m2) a=h*60+m b=h2*60+m2 if a<=b: ANS+=b-a else: ANS+=b+(24*60)-a print(ANS)