import java.util.*; 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 sleep = sc.next(); String wake = sc.next(); String[] s = sleep.split(":"); String[] w = wake.split(":"); int H = Integer.parseInt(s[0]); int M = Integer.parseInt(s[1]); int h = Integer.parseInt(w[0]); int m = Integer.parseInt(w[1]); int sleepT = 60 * H + M; int wakeT = 60 * h + m; if(wakeT >= sleepT) { ans += (wakeT - sleepT); } else { ans += (60 * 24 - (sleepT - wakeT)); } } System.out.println(ans); } }