#include using namespace std; int main(int argc, const char* argv[]) { int N; cin >> N; int sum = 0; for (int i = 0; i < N; i++) { int H, M, h, m; scanf("%d:%d %d:%d", &H, &M, &h, &m); if (H <= h && M <= m) { } else { sum += 24 * 60; } sum += (h - H) * 60 + (m - M); } cout << sum << endl; return 0; }