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 sleepHour = Integer.parseInt(sleep[0]);
            int wakeupHour = Integer.parseInt(wakeup[0]);
            int sleepMinute = Integer.parseInt(sleep[1]);
            int wakeupMinute = Integer.parseInt(wakeup[1]);
            if (sleepHour > wakeupHour || sleepHour == wakeupHour && sleepMinute > wakeupMinute) {
                wakeupHour += 24;
            }
            minutes += (wakeupHour - sleepHour) * 60 + wakeupMinute - sleepMinute;
        }
        System.out.println(minutes);
    }
}