import java.util.*;

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