using System; using System.IO; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Numerics; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; using static System.Console; namespace yukicoder { class Program { static void Main() { var n = int.Parse(Console.ReadLine()); var day = 1440; var sleep = 0; for (int i = 0; i < n; i++) { var t = Console.ReadLine().Split(' '); var t1 = t[0].Split(":"); var t2 = t[1].Split(":"); var startHour = int.Parse(t1[0]) * 60; var startMinute = int.Parse(t1[1]); var endHour = int.Parse(t2[0]) * 60; var endMinute = int.Parse(t2[1]); if (startHour > endHour) { sleep += day - ((startHour + startMinute) - (endHour + endMinute)); } else { sleep += (endHour + endMinute) - (startHour + startMinute); } } Console.WriteLine(sleep); } } }