P29695 [洛谷] [COCI2013-2014#2] VOLIM
普及-
题目描述

Problem Description

There are 8 people sitting in a circle, as shown in the figure.

Figure

One of them holds a box that will explode 210 seconds after the game starts.

The host will ask the person holding the box questions, and the person can choose the following actions:

  • If the person skips or answers incorrectly, the host will proceed to the next question.
  • If the person answers correctly, the box is passed to the person immediately to their left, who becomes the new holder of the box.

You are given the initial holder's number and the number of questions, as well as the time taken and the outcome for each question.

Determine the number of the person holding the box when it explodes.

The time taken to pass the box and the interval between questions are negligible. The data guarantees that the box will explode while in someone's hands, and not all questions will be asked.

Input Format

The first line contains an integer $K$, the initial holder's number.

The second line contains an integer $N$, the number of questions.

The next $N$ lines each contain an integer $T$ and a character, representing the time taken and the outcome of the question:

  • The character T indicates a correct answer.
  • The character N indicates an incorrect answer.
  • The character P indicates a skipped question.

Output Format

Output a single integer, the number of the person holding the box when it explodes.

Sample Input and Output

Sample Input #1

1 
5 
20 T 
50 T 
80 T 
50 T 
30 T

Sample Output #1

5

Sample Input #2

3 
5 
100 T 
100 N 
100 T 
100 T 
100 N

Sample Output #2

4

Sample Input #3

5
6
70 T
50 P
30 N
50 T
30 P
80 T

Sample Output #3

7

Notes

Data Constraints

For $100\%$ of the data, $1 \le K \le 8$, $1 \le N, T \le 100$.

Source

This problem is adapted from COCI2013-2014 CONTEST 2 T1 VOLIM.

According to the original problem data configuration, this problem is worth $50$ points.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
1 5 20 T 50 T 80 T 50 T 30 T
样例输出
5