#include inline long nextInt(void) { long temp; std::cin >> temp; return temp; } int main() { int N; int a, b, c, d; int ans = 0; int temp; std::cin >> N; for(int i = 0; i < N; ++i) { scanf("%d:%d %d:%d", &a, &b, &c, &d); c += 24; temp = (c * 60 + d) - (a * 60 + b); temp %= 24 * 60; ans += temp; } std::cout << ans << std::endl; return 0; }