import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); long ans = 0; for (int i = 0; i < n; i++) { int start = getTime(sc.next()); int end = getTime(sc.next()); ans += (end - start + 60 * 24) % (60 * 24); } System.out.println(ans); } static int getTime(String s) { String[] arr = s.split(":", 2); return Integer.parseInt(arr[0]) * 60 + Integer.parseInt(arr[1]); } }