class Program { static void Main(string[] args) { int count = int.Parse(Console.ReadLine()!); int sleepMinute = 0; int sleepHour = 0; for (int i = 0; i < count; i++) { string[] input = Console.ReadLine()!.Split(' '); TimeSpan start = TimeSpan.Parse(input[0]); TimeSpan wakeup = TimeSpan.Parse(input[1]); int startHour = start.Hours; int wakeupHour = wakeup.Hours; int startMinute = start.Minutes; int wakeupMinute = wakeup.Minutes; if (startHour == wakeupHour && startMinute < wakeupMinute) { sleepMinute = wakeupMinute - startMinute; } else if(startHour == wakeupHour && startMinute > wakeupMinute) { sleepHour += 23; sleepMinute = 60 - wakeupMinute; } else if(startMinute != wakeupMinute) { sleepMinute += 60 - startMinute + wakeupMinute; } if (wakeupHour < startHour) { sleepHour += 23 - startHour + wakeupHour; } else { sleepHour += wakeupHour - startHour; } if (sleepMinute >= 60) { sleepHour += 1; sleepMinute -= 60; } } Console.WriteLine(sleepHour * 60 + sleepMinute); } }