import java.io.*; import java.util.*; import java.math.*; class Main { public static void out (Object o) { System.out.println(o); } public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int ans = 0; for (int i = 0; i < n; i++) { String[] line = br.readLine().split(" "); String[] time1 = line[0].split(":"); String[] time2 = line[1].split(":"); int h1 = Integer.parseInt(time1[0]); int m1 = Integer.parseInt(time1[1]); int h2 = Integer.parseInt(time2[0]); int m2 = Integer.parseInt(time2[1]); int t1 = h1 * 60 + m1; int t2 = h2 * 60 + m2; ans += t1 <= t2 ? t2 - t1 : 1440 - (t1 - t2); } out(ans); } }