# -*- coding: utf-8 -*- def calc(H, M, h, m): S = 60 * H + M B = 24 * 60 if H <= h: W = 60 * h + m else: W = 60 * h + m + B if W < S: W += 24 * 60 return W - S N = input() tot = 0 for i in range(0, N): S, W = raw_input().split() H, M = map(int, S.split(":")) h, m = map(int, W.split(":")) tot += calc(H, M, h, m) print tot