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 st = Integer.valueOf(time[2]) * 60 + Integer.valueOf(time[3]); int en = Integer.valueOf(time[0]) * 60 + Integer.valueOf(time[1]); if(en < st) { en += 24 * 60; } ans += en - st; } System.out.println(ans); } }