#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define REP(i,n) for(long (i)=0;(i)<(n);(i)++) #define FOR(i,a,b) for(long (i)=(a);(i)<(b);(i)++) #define RREP(i,a) for(long (i)=(a)-1;(i)>=0;(i)--) #define FORR(i,a,b) for(long (i)=(a)-1;(i)>=(b);(i)--) #define MOD 1000000007 #define PI acos(-1.0) #define DEBUG(C) cout< #define PLL pair #define ALL(a) (a).begin(),(a).end() #define SORT(a) sort((a).begin(),(a).end()) #define RSORT(a) sort((a).begin(),(a).end(),greater()) typedef long long LL; typedef unsigned long long ULL; using namespace std; int main(void){ int N; cin>>N; int hm[N][4]; REP(i,N){ scanf("%d:%d %d:%d",&hm[i][0],&hm[i][1],&hm[i][2],&hm[i][3]); } long ans=0; REP(i,N){ if(hm[i][0]>hm[i][2]){ ans+=(24-hm[i][0])*60; ans+=hm[i][2]*60; }else{ ans+=(hm[i][2]-hm[i][0])*60; } ans=ans-hm[i][1]+hm[i][3]; } cout<