#include #include #include using namespace std; typedef long long int ll; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; int ans=0; while(n--){ int a,b,c,d; char z; cin >> a >> z >> b >> c >> z >> d; int e=a*60+b,f=c*60+d; if(e>f){ f+=60*24; } ans+=f-e; } cout << ans << endl; }