#include using namespace std; using ll = long long; #define rep(i, s, e) for (int i = (int)s; i < (int)e; ++i) #define all(a) (a).begin(), (a).end() int main() { cin.tie(nullptr); int N; cin >> N; ll ans = 0; rep(days, 0, N) { string S, E; cin >> S >> E; int H, M, h, m; string tmp = ""; int i = 0; while (true) { if (S[i] == ':') break; tmp += S[i]; i++; } i++; H = stoi(tmp); tmp = ""; rep(j, i, S.size()) tmp += S[j]; M = stoi(tmp); tmp = ""; i = 0; while (true) { if (E[i] == ':') break; tmp += E[i]; i++; } i++; h = stoi(tmp); tmp = ""; rep(j, i, E.size()) tmp += E[j]; m = stoi(tmp); int s = H * 60 + M; int e = h * 60 + m; if (e - s >= 0) { ans += e - s; continue; } e += 24 * 60; ans += e - s; } cout << ans << '\n'; }