#include using namespace std; int main() { int N; cin >> N; int ans = 0; for (int i = 0; i < N; i++) { int a, b, c, d; char e; cin >> a >> e >> b >> c >> e >> d; int x = a * 60 + b; int y = c * 60 + d; ans += min(abs(x - y), 1440 - abs(x - y)); } cout << ans << "\n"; }