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()); int sumHour[] = {0}; int sumMin[] = {0}; for (int i = 0; i < N; i++) { String G = sc.next(); String W = sc.next(); int Gh = Integer.parseInt(G.split(":")[0]); int Gm = Integer.parseInt(G.split(":")[1]); int Wh = Integer.parseInt(W.split(":")[0]); int Wm = Integer.parseInt(W.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]); } }