import java.util.Scanner; public class Yukicoder70 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String s; String[] buf, buf2; int h1, m1, h2, m2; int sum = 0; for (int i = 0; i < n; i++) { buf = sc.next().split(":"); h1 = Integer.parseInt(buf[0]); m1 = Integer.parseInt(buf[1]); buf = sc.next().split(":"); h2 = Integer.parseInt(buf[0]); m2 = Integer.parseInt(buf[1]); sum += h1 > h2 ? (h2 - h1 + 24) * 60 : (h2 - h1) * 60; sum += m2 - m1; } System.out.println(sum); } }