#include #define rep(i, n) for(long long i = 0; i < (long long)n; i++) #define ALL(v) (v).begin(), (v).end() #define rALL(v) (v).rbegin(), (v).rend() using namespace std; using lint = long long; using ld = long double; int main() { int n; cin >> n; int ans = 0; auto calc = [](int a, int b, int c, int d) -> int { if (a > c || (a == c && b > d)) { c += 24; } if (b > d) { c--; d += 60; } return (c - a) * 60 + (d - b); }; while (n--) { string s, t; cin >> s >> t; int x, y; rep(i, (int)s.size()) { if (s[i] == ':') { x = i; } } rep(i, (int)t.size()) { if (t[i] == ':') { y = i; } } int a = stoi(s.substr(0, x)), b = stoi(s.substr(x + 1)); int c = stoi(t.substr(0, y)), d = stoi(t.substr(y + 1)); ans += calc(a, b, c, d); } cout << ans << endl; }