using System; class Program { static void Main() { int n = int.Parse(Console.ReadLine()); int[] H = new int[n]; int[] M = new int[n]; int[] h = new int[n]; int[] m = new int[n]; for (int i = 0; i < n; i++) { string[] s = Console.ReadLine().Split(); H[i] = int.Parse(s[0].Split(':')[0]); M[i] = int.Parse(s[0].Split(':')[1]); h[i] = int.Parse(s[1].Split(':')[0]); m[i] = int.Parse(s[1].Split(':')[1]); } int sleep = 0; for (int i = 0; i < n; i++) { if (H[i] > h[i] || (H[i] == h[i] && M[i] > m[i])) h[i] += 24; sleep += h[i] * 60 + m[i] - H[i] * 60 - M[i]; } Console.WriteLine(sleep); } }