import java.util.*; public class Run { public static void main (String arg[]) { Scanner scan = new Scanner(System.in); scan.useDelimiter("[^0-9]"); int N = scan.nextInt(); if (N < 1||N > 30) System.exit(1); int hsum = 0; int msum = 0; for (int i = 0; i < N; i++) { int H = scan.nextInt(); int M = scan.nextInt(); int h = scan.nextInt(); int m = scan.nextInt(); hsum += (h - H + 24)%24; msum += m - M; if (msum > 59) { hsum++; msum -= 60; } else if (msum < 0) { hsum--; msum += 60; } } System.out.println(hsum*60 + msum); } }