# -*- coding: utf-8 -*- n = int(input()) H = [0] * n M = [0] * n h = [0] * n m = [0] * n for i in range(n): temp1,temp2 = list(input().split()) H[i],M[i] = map(int,temp1.split(":")) h[i],m[i] = map(int,temp2.split(":")) def timelen(h1,m1,h2,m2): m1 += h1 * 60 m2 += h2 * 60 m = m2 - m1 if m < 0: m += 1440 return m ans = 0 for i in range(n): ans += timelen(H[i],M[i],h[i],m[i]) print(ans)