#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef pair Pr; int N; ll ans = 0; int main() { cin >> N; for (int i = 0; i < N; i++) { ll H, M, h, m; scanf("%lld:%lld %lld:%lld",&H,&M,&h,&m); if (H == h) { if (M < m) { ans += m; } else { ans += 23 * 60 + 60 - M; } } else if (H < h) { ans += (h * 60 + m) - (H * 60 + M); } else { ans += (23 - H) * 60 + (60-M )+ h * 60 + m; } } cout << ans << endl; return 0; }