#include int main(){ int n,H,M,h,m,r=0; for(scanf("%d",&n);n--;){ scanf("%d%d%d%d",&H,&M,&h,&m); M+=H*60,m+=h*60; r+=m-M; } printf("%d\n",r); return 0; }