using System;
using System.Linq;
using System.Collections.Generic;

class Program {
    static void Main() {
        int n = int.Parse(Console.ReadLine());
        int sleepTime = 0;
        for (int i = 0; i < n; i++) {
            int[] a = Console.ReadLine().Split(':', ' ').Select(int.Parse).ToArray();
            if(a[0] > a[2] || a[0] == a[2] && a[1] > a[3]) {
                sleepTime += (a[2] + 24) * 60 + a[3] - (a[0] * 60 + a[1]);
            } else {
                sleepTime += a[2] * 60 + a[3] - (a[0] * 60 + a[1]);
            }
        }
        Console.WriteLine(sleepTime);
    }
}