#include #include #include using namespace std; using ll = long long; //70 int main() { int n, h[2], m[2], time[2], slept, total = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d:%d %d:%d", h, m, h + 1, m + 1); time[0] = h[0] * 60 + m[0]; time[1] = h[1] * 60 + m[1]; slept = time[1] - time[0]; if (slept < 0) slept = slept + 24 * 60; total += slept; } printf("%d\n", total); }