#include using namespace std; int main() { int N; cin >> N; cin.ignore( numeric_limits::max(), '\n' ); int ans = 0; for( int i = 0; i < N; i++ ) { string buf; getline( cin, buf ); int H, M, h, m; sscanf( buf.c_str(), "%d:%d %d:%d", &H, &M, &h, &m ); if( h < H || h == H && m < M ) h += 24; int st = H * 60 + M; int end = h * 60 + m; ans += end - st; } cout << ans << endl; }