import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int ans = 0; for(int i = 0 ; i < n ; i++) { String[] temp = (sc.next() + ":" + sc.next()).split("[\\:]"); int[] time = {Integer.valueOf(temp[0]), Integer.valueOf(temp[1]) , Integer.valueOf(temp[2]), Integer.valueOf(temp[3])}; int st = time[0] * 60 + time[1]; int en = (time[2] * 60 + time[3]) + 24 * 60; ans += (en - st) % (24 * 60); } System.out.println(ans); } }