#include #include #include using namespace std; int main(){ int n; int a,b; int H, h, M, m; int dh, dm; int ans = 0; string s1; string s2; cin >> n; for (int i = 0; i < n; i++){ cin >> s1; cin >> s2; a = s1.find(":"); if (a == 1){ H = s1[0] - '0'; if (s1[3] == '\0'){ M = s1[2] - '0'; } else{ M = (s1[2] - '0') * 10 + (s1[3] - '0'); } } else{ H = (s1[0] - '0') * 10 + (s1[1] - '0'); if (s1[4] == '\0'){ M = s1[3] - '0'; } else{ M = (s1[3] - '0') * 10 + (s1[4] - '0'); } } b = s2.find(":"); if (b == 1){ h = s2[0] - '0'; if (s2[3] == '\0'){ m = s2[2] - '0'; } else{ m = (s2[2] - '0') * 10 + (s2[3] - '0'); } } else{ h = (s2[0] - '0') * 10 + (s2[1] - '0'); if (s2[4] == '\0'){ m = s2[3] - '0'; } else{ m = (s2[3] - '0') * 10 + (s2[4] - '0'); } } dh = h - H; dm = m - M; if (dm < 0){ dm += 60; dh -= 1; } if (dh < 0){ dh += 24; } ans += dh * 60 + dm; } cout << ans << endl; return 0; }