n, m = map(int, input().split())
teamname = 'NijeZivotJedanACM'
timovi = []
lines = []
for i in range(n):
lines.append(input())
lines.append(input())
for i in range(n):
line = lines[i].split()
name = line[0]
if name == teamname:
line = lines[n].split()
tasks = []
for j in range(1, m + 1):
task = line[j]
solved = task[0]
if solved != '-' and name != teamname:
solved = True
elif name == teamname and solved == '+':
solved = True
else:
solved = False
sent = 0
if len(task) != 1:
sent = int(task[1])
time = 0
if solved:
time = [int(k) for k in task[3:].split(':')]
time = time[0] * 3600 + time[1] * 60 + time[2]
time += (sent - 1) * 1200
tasks.append((-1 * solved, time))
solved = 0
time = 0
for t in tasks:
solved += t[0]
time += t[1]
timovi.append((solved, time, name))
timovi.sort()
#print(timovi)
for i in range(len(timovi)):
if timovi[i][2] == teamname:
print(i + 1)
break