#include using namespace std; int main() { int n, ans = 0; cin >> n; for (int i = 0; i < n; i++) { int h0, m0, h1, m1; scanf("%d:%d %d:%d", &h0, &m0, &h1, &m1); ans += (60 * h1 + m1 - 60 * h0 - m0 + 86400) % (24 * 60); } cout << ans << endl; }