import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class Main { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int N = Integer.parseInt(reader.readLine()); int sum = 0; for (int i = 0; i < N; i++) { String[] inputs = reader.readLine().split(" "); String[] sleepTime = inputs[0].split(":"); String[] wakeUpTime = inputs[1].split(":"); int H1 = Integer.parseInt(sleepTime[0]); int M1 = Integer.parseInt(sleepTime[1]); int h1 = Integer.parseInt(wakeUpTime[0]); int m1 = Integer.parseInt(wakeUpTime[1]); int a = H1 * 60 + M1; int b = h1 * 60 + m1; if (a > b) { sum +=b - a + 1440; } else { sum += b-a; } } System.out.println(sum); } }