#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
  int n;
  while(scanf("%d",&n) , n){
    bool login[1001] = {};
    int cost[1001] = {}, prev[1001];
    while(n--){
      int time, U, h, m, id;
      char buff;
      scanf("%d/%d %d:%d %c %d",&U,&U,&h,&m,&buff,&id);
      time = h * 60 + m;
      if(login[id]){
        if(!id) for(int i = 1 ; i < 1001 ; i++ ){
          if(login[i]) cost[i] += time - max(prev[0],prev[i]);
        }else if(login[0]) cost[id] += time - max(prev[0],prev[id]);
      }else prev[id] = time;
      login[id] = !login[id];
    }
    printf("%d\n",*max_element(cost+1,cost+1000));
  }
}