#include using namespace std; int main(){ int ans = 0,n; char colon; cin >> n; for(int i = n,H,M,h,m;i--;){ cin >> H >> colon >> M >> h >> colon >> m; while(H != h || M != m){ ans++; if(++M == 60){ M = 0; if(++H == 24) H = 0; } } } cout << ans << endl; }