# Arup Guha
# 1/25/2025
# Solution to Kattis Problem: Volim
# https://open.kattis.com/problems/volim

# Do 0 based indexing of players so we can use mod.
idx = int(input()) - 1

# Number of questions.
n = int(input())

# Just store the transcript without processing.
transcript = []
for i in range(n):
    toks = input().split()
    transcript.append(toks)

# Starting results for simulation
res = idx
curT = 0

# Now simulate.
for i in range(n):

    # Update the current time.
    curT += int(transcript[i][0])

    # Time's up!
    if curT >= 210:
        res = idx
        break

    # We only change the player if they got the question correct.
    if transcript[i][1] == 'T':
        idx = (idx+1)%8

# Ta da!
print(res+1)
