#include using namespace std; signed main(){ int ans=0; int n;cin>>n; while(n--){ int H,M,h,m;char c; cin>>H>>c>>M>>h>>c>>m; if(H>h)h+=24; ans+=h*60+m-H*60-M; } cout<