#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
  /*int N, M; cin >> N >> M;
  for (int i = 0; i < N; ++i) {
    int x, y; cin >> x >> y;
  }
  for (int i = 0; i < M; ++i) {
    int p, q; cin >> p >> q;
  }*/
  
  while (1) {
    int N; cin >> N;
    if (!N)break;

    vector<long long int>times(1000);
    int preminute = 0;
    vector<bool>isin(1000);
    for (int i = 0; i < N; ++i) {
      string day, time, inout, num; cin >> day >> time >> inout >> num;
      const int minute = stoi(time.substr(0, 2)) * 60 + stoi(time.substr(3, 2));
      const int prayer = stoi(num);
      bool in = inout == "I";
      if (isin[0]) {
        for (int i = 1; i < 1000; ++i) {
          if (isin[i])times[i] += minute - preminute;
        }
      }
      isin[prayer] = in;
      preminute = minute;
    }
    long long int ans = *max_element(times.begin(), times.end());
    cout << ans << endl;
  }
  return 0;
}