#include <stdio.h>
#include <string.h>

int main(void) {
	int n;
	int i,j;
	int times[1000];
	int last[1000];
	int now[1000];
	int month,day,hour,minute;
	char io[4];
	int id;
	int now_time;
	int max;
	while(1) {
		scanf("%d",&n);
		if(n==0)break;
		memset(times,0,sizeof(times));
		memset(last,0,sizeof(last));
		memset(now,0,sizeof(now));
		for(i=0;i<n;i++) {
			scanf("%d/%d %d:%d %s %d",
				&month,&day,&hour,&minute,io,&id);
			now_time=hour*60+minute;
			if(io[0]=='I') {
				now[id]=1;
			} else {
				if(id==0) {
					for(j=1;j<1000;j++) {
						if(now[j]) {
							times[j]+=now_time-
								(last[0]>last[j]?last[0]:last[j]);
						}
					}
				} else {
					if(now[0]) {
						times[id]+=now_time-
							(last[0]>last[id]?last[0]:last[id]);
					}
				}
				now[id]=0;
			}
			last[id]=now_time;
		}
		max=0;
		for(i=1;i<1000;i++) {
			if(times[i]>max)max=times[i];
		}
		printf("%d\n",max);
	}
	return 0;
}