import java.util.Arrays; import java.util.LinkedList; import java.util.Scanner; public class Main { // やるだけ. public static void main(String[] args){ Scanner sc = new Scanner(System.in); final int N = sc.nextInt(); long sum = 0; for(int i = 0; i < N; i++){ final String[] ins = sc.next().split(":"); final String[] outs = sc.next().split(":"); final int H = Integer.parseInt(ins[0]); final int M = Integer.parseInt(ins[1]); final int T = H * 60 + M; final int h = Integer.parseInt(outs[0]); final int m = Integer.parseInt(outs[1]); final int t = h * 60 + m; //System.out.println(T + " " + t); sum += (T >= t ? (24 * 60 - T + t) : (t - T)); } System.out.println(sum); } }