#include using namespace std; #define REP(i,a,b) for(int i=a;i<(int)b;i++) #define rep(i,n) REP(i,0,n) int main() { int N; cin >> N; int sum = 0; rep(i, N) { char ch; int H, M, h, m; cin >> H >> ch >> M >> h >> ch >> m; if(h < H) { h += 24; } sum += (h-H) * 60 + (m-M); } cout << sum << endl; return 0; }