#include #include #include #include using namespace std; int toint(string s){ stringstream ss(s); int ret; ss >> ret; return ret; } int main(){ int n; cin >> n; int ans = 0; for(int i = 0;i < n;i++){ string s,e; cin >> s >> e; int sh,st,eh,et;char damy; stringstream ss(s); stringstream es(e); ss >> sh >> damy >> st; es >> eh >> damy >> et; st = sh * 60 + st; et = eh * 60 + et; if(st > et) ans += 24 * 60 - st + et; else ans += et - st; } cout << ans << endl; return 0; }