#coding: utf-8 ##yuki_70 def hm(s): if len(s)==5: h=s[0]+s[1] m=s[3]+s[4] elif len(s)==4: if s[1]==':': h='0'+s[0] m=s[2]+s[3] elif s[2]==':': h=s[0]+s[1] m='0'+s[3] elif len(s)==3: h='0'+s[0] m='0'+s[2] return int(h)*60+int(m) #minutes n=int(raw_input()) res=0 for i in xrange(n): t=raw_input().split() et=0 et=hm(t[1])-hm(t[0]) if et<0: et=et+60*24 res+=et print res