#include using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; int answer = 0; while(N--){ string s; cin >> s; int one = 0,two = 0; for(auto c : s){ if(c == ':') swap(one,two); else one *= 10,one += c-'0'; } swap(one,two); int now = 0; now += (23-one)*60; now += 60-two; cin >> s; one = 0,two = 0; for(auto c : s){ if(c == ':') swap(one,two); else one *= 10,one += c-'0'; } swap(one,two); now += one*60+two; now %= 1440; answer += now; } cout << answer << endl; }