// AOJ 1315: Gift from the Goddess of Programming
// 2017.10.4 bal4u@uu

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

#define MAX(a,b) ((a)>=(b)?(a):(b))

int tm[1002], s[1002];
char in[1002];

int main()
{
	int n, i, hh, mm, t, p, max, ans;
	char date[10], time[10], e[5];

	while (scanf("%d", &n) && n > 0) {
		max = 0; memset(in, 0, sizeof(in)), memset(s, 0, sizeof(s));
		while (n-- > 0) {
			scanf("%s%s%s%d", date, time, e, &p);
			hh = atoi(time), mm = atoi(time+3);
			t = hh*60 + mm;
			if (*e == 'I') tm[p] = t, in[p] = 1;
			else {
				in[p] = 0;
				if (p == 0) {
					for (i = 1; i <= max; i++) {
						if (in[i]) s[i] += t - MAX(tm[0], tm[i]);
					}
				} else if (in[0]) s[p] += t - MAX(tm[0], tm[p]);
			}
			if (p > max) max = p;
		}
		for (ans = 0, i = 1; i <= max; i++) if (s[i] > ans) ans = s[i];
		printf("%d\n", ans);
	}
	return 0;
}