class Time: def __init__(self, s: str) -> None: f = s.find(":") self.h = int(s[0:f]) self.m = int(s[f+1:]) def __add__(self, other): time = Time("00:00") time.h = self.h+other.h time.m = self.m+other.m time.h += int(time.m/60) time.m %= 60 return time def __sub__(self, other): time = Time("00:00") time.h = self.h-other.h time.m = self.m-other.m if time.m < 0: time.h -= 1 time.m %= 60 time.h %= 24 return time def show(self): print(f"{self.h}:{self.m}") def __str__(self): return str(self.h*60+self.m) def main(): cnt = Time("00:00") n = int(input()) for i in range(n): a, b = input().split() cnt += (Time(b)-Time(a)) print(cnt) # cnt.show() if __name__ == "__main__": main()