#!/usr/bin/env python3 #fileencoding: utf-8 N = int(input()) total = 0 for i in range(N): slp, wkup = input().strip().split(" ") slp_h, slp_m = [int(j) for j in slp.split(":")] wkup_h, wkup_m = [int(j) for j in wkup.split(":")] if slp_h > wkup_h or ((slp_h == wkup_h) and (slp_m > wkup_m)): wkup_h += 24 slp_time = slp_h * 60 + slp_m wkup_time = wkup_h * 60 + wkup_m total += (wkup_time - slp_time) print(total)