import java.util.*;

class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		
		int n = sc.nextInt();
		int sum = 0;
		for (int i=0; i<n; i++) {
			String[] a = sc.next().split(":",0);
			String[] b = sc.next().split(":",0);
			int t1 = Integer.parseInt(a[0])*60 + Integer.parseInt(a[1]);
			int t2 = Integer.parseInt(b[0])*60 + Integer.parseInt(b[1]);
			int t = (t2-t1+1440)%1440;
			sum += t;
		}
		System.out.println(sum);
		
	}
}