#include <bits/stdc++.h>
using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	int n;
	scanf("%d", &n);
	long long s = 0;
	while(n--) {
		int a, b, c, d;
		scanf("%d:%d%d:%d", &a, &b, &c, &d);
		s += (c * 60 + d - (a * 60 + b) + 1440) % 1440;
	}
	cout << s << endl;
	return 0;	
}