import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int ans = 0; for(int i = 0 ; i < n ; i++) { String[] time = (sc.next() + ":" + sc.next()).split(":"); int h = (Integer.valueOf(time[2]) + 24 - Integer.valueOf(time[0])) % 24; int m = Integer.valueOf(time[3]) - Integer.valueOf(time[1]); ans += h * 60 + m; } System.out.println(ans); } }