#include #define rep(i, a, n) for (int i = a; i < n; i++) #define repr(i, a, n) for (int i = n - 1; i >= a; i--) using namespace std; using ll = long long; using P = pair; template void chmin(T &a, T b) { a = min(a, b); } template void chmax(T &a, T b) { a = max(a, b); } int time_convert(string d) { int sp = d.find(':'); int one = stoi(d.substr(0, sp)); int two = stoi(d.substr(sp + 1, d.size() - (sp + 1))); return one * 60 + two; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int ans = 0; rep(i, 0, n) { string a, b; cin >> a >> b; int start = time_convert(a); int end = time_convert(b); if (start > end) ans += end + (1440 - start); else ans += end - start; } cout << ans << endl; }