#define REP(i, n) for(int i = 0;i < n;i++) #define REPR(i, n) for(int i = n;i >= 0;i--) #define FOR(i, m, n) for(int i = m;i < n;i++) #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; vector split(string s, string delim) { vector res; int pos = 0; while(true) { int found = s.find(delim, pos); if(found >= 0) { res.push_back(s.substr(pos, found - pos)); } else { res.push_back(s.substr(pos)); break; } pos = found + delim.size(); } return res; } int main() { int n,ans; cin >> n; string a,b; vector a0,b0; string thresh = ":"; ans = 0; int a1,a2,b1,b2; int hr,mn; REP(i,n){ cin >> a >> b; a0 = split(a, thresh); b0 = split(b, thresh); a1 = stoi(a0[0]); a2 = stoi(a0[1]); b1 = stoi(b0[0]); b2 = stoi(b0[1]); hr = b1-a1; if(hr < 0) hr += 24; mn = b2-a2; if(mn < 0){ mn += 60; hr -= 1; } } cout << mn+hr*60 << endl; return 0; }