#include <iostream> using namespace std; int main() { int n, sumH=0, sumM=0; cin >> n; for (int i=0; i<n; i++) { int H, M, h, m; scanf("%d:%d %d:%d", &H, &M, &h, &m); if (H>h) { sumH+=24-(H+1)+h; sumM+=60-M+m; } else if (H<h) { sumH+=h-H-1; sumM+=60-M+m; } else { if (M<m) { sumM+=m-M; } else { sumH+=23; sumM+=60-M; } } } cout << sumH*60+sumM << endl; return 0; }