import java.util.Scanner; public class No70 { public static void main(String[] args) { Scanner s = new Scanner(System.in); int count = s.nextInt(); int minutes = 0; for (int i = 0; i < count; i++) { String[] sleep = s.next().split(":"); String[] wakeup = s.next().split(":"); int wakeupHour = Integer.parseInt(wakeup[0]); int sleepHour = Integer.parseInt(sleep[0]); if (sleepHour > wakeupHour) { wakeupHour += 24; } minutes += (wakeupHour - sleepHour) * 60 + Integer.parseInt(wakeup[1]) - Integer.parseInt(sleep[1]); } System.out.println(minutes); } }