import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class No00000070_Main { 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[] timeArr = br.readLine().split(" "); ans += getSleepTime(timeArr); } System.out.println(ans); } private static int getSleepTime(String[] arr) { int h1 = Integer.parseInt(arr[0].split(":")[0]); int m1 = Integer.parseInt(arr[0].split(":")[1]); int h2 = Integer.parseInt(arr[1].split(":")[0]); int m2 = Integer.parseInt(arr[1].split(":")[1]); if(m1 > m2) { h2--; m2 += 60; } if(h1 > h2) { h2 += 24; } return (h2 - h1) * 60 + (m2 - m1); } }