#include <bits/stdc++.h>
using namespace std;

int main() {
  for(int n; cin >> n && n; ) {
    vector<int> in(1000, 0), sum(1000, 0);
    int prev = 0;
    while(n--) {
      int h, m, id; char c;
      cin >> h >> c >> h >> h >> c >> m >> c >> id;
      m += h * 60;
      for(int i = 1; in[0] && i < 1000; ++i) {
        if(in[i]) sum[i] += m - prev;
      }
      in[id] = c == 'I';
      prev = m;
    }
    cout << *max_element(sum.begin(), sum.end()) << endl;
  }
  return 0;
}