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(":"); ans += ((Integer.valueOf(time[2]) + 24 -Integer.valueOf(time[0])) % 24) * 60 + Integer.valueOf(time[3]) - Integer.valueOf(time[1]); } System.out.println(ans); } }