#include using namespace std; int main() { int N; cin >> N; int ans = 0; for (int i = 0; i < N; ++i) { int h1, m1, h2, m2; char c; cin >> h1 >> c >> m1 >> h2 >> c >> m2; int t = (h2 - h1) * 60 + m2 - m1; ans += t; if (t < 0) ans += 24 * 60; } cout << ans << endl; return 0; }