import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = Integer.parseInt(sc.next()); Map sleeps = new HashMap<>(); for (int i = 0; i < N; i++) { String G = sc.next(); String W = sc.next(); sleeps.put(G, W); } int sumHour[] = {0}; int sumMin[] = {0}; sleeps.forEach((s, s2) -> { int Gh = Integer.parseInt(s.split(":")[0]); int Gm = Integer.parseInt(s.split(":")[1]); int Wh = Integer.parseInt(s2.split(":")[0]); int Wm = Integer.parseInt(s2.split(":")[1]); if (Wh - Gh < 0) { sumHour[0] += ((24 - Gh) + Wh) - 1; } else { sumHour[0] += Wh - Gh - 1; } sumMin[0] += 60 - Gm + Wm; sumHour[0] += sumMin[0] / 60; sumMin[0] %= 60; }); System.out.println(sumHour[0]*60 + sumMin[0]); } }