package me.yukicoder; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class No0070 { public static void main(String[] args) { try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) { int h = 0, m = 0; int cnt = Integer.parseInt(br.readLine()); int sum = 0; for (int i = 0; i < cnt; i++) { String[] input = br.readLine().split(" "); String[] str1 = input[0].split(":"); String[] str2 = input[1].split(":"); int[] bedtime = {Integer.parseInt(str1[0]), Integer.parseInt(str1[1])}; int[] wakeuptime = {Integer.parseInt(str2[0]), Integer.parseInt(str2[1])}; if (bedtime[0] > wakeuptime[0]) { wakeuptime[0] += 24; } if (bedtime[1] > wakeuptime[1]) { wakeuptime[1] += 60; wakeuptime[0] -= 1; } h += wakeuptime[0] - bedtime[0]; m += wakeuptime[1] - bedtime[1]; } System.out.println(h * 60 + m); } catch (IOException e) { e.printStackTrace(); } } }