#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;


int timesum[1001];
int entry[1001];
int main(void) {
    // cin.tie(0); ios::sync_with_stdio(false);
    int n;
    while(cin >> n,n){
        vector<int> M(n),D(n),h(n),m(n);
        vector<string> e(n);
        vector<int> p(n);
        char c;
        for(int i = 0; i < n;i++){
            cin >> M[i] >> c >> D[i] >> h[i] >> c >> m[i] >> e[i] >> p[i];
        }
        fill(timesum,timesum+1001,0);
        fill(entry,entry+1001,-1);
        
        for(int i = 0; i < n;i++){
            
            if(e[i] == "I"){
                entry[p[i]] = h[i] * 60 + m[i];
            }else{
                int time = h[i] * 60 + m[i];
                
                if(p[i] == 0){
                    for(int j = 1; j <= 1000; j++){
                        if(entry[j] == -1) continue;
                        timesum[j] += time-max(entry[0],entry[j]);
                    }
                    
                }else{
                    if(entry[0] != -1 && entry[p[i]] != -1){
                        timesum[p[i]] += time - max(entry[0],entry[p[i]]);
                    }
                }
                entry[p[i]] = -1;
            }
        }
        cout << *max_element(timesum, timesum+101) << endl;
    }
    return 0;
}

