#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main() {
  int current, questions, total_time = 0, explode = -1;
  scanf("%d", &current);
  scanf("%d", &questions);
  while (questions-- > 0) {
    int time;
    char result;
    scanf("%d %c", &time, &result);
    total_time += time;
    if (total_time >= 210 && explode < 0)
      explode = current;
    if (result == 'T')
      current = current == 8 ? 1 : current + 1;
  }
  printf("%d\n", explode);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
lea    0xebc(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xeaa(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
jle    11e9 <main+0xc9>
lea    0xe87(%rip),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x19(%rbp),%rdx
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x18(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0xd2,-0x10(%rbp)
jl     11b1 <main+0x91>
cmpl   $0x0,-0x14(%rbp)
jge    11b1 <main+0x91>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0x54,%eax
jne    11e4 <main+0xc4>
cmpl   $0x8,-0x8(%rbp)
jne    11d5 <main+0xb5>
mov    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11de <main+0xbe>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    1161 <main+0x41>
mov    -0x14(%rbp),%esi
lea    0xe16(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xecb(%rip),%rbx
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <scanf@plt>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0xc(%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,0xc(%rsp)
mov    $0xffffffff,%r13d
test   %eax,%eax
jle    11d6 <main+0xb6>
lea    0xe94(%rip),%r14
lea    0x14(%rsp),%r15
lea    0xb(%rsp),%r12
xor    %ebp,%ebp
jmp    118f <main+0x6f>
nopl   (%rax)
mov    0xc(%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,0xc(%rsp)
test   %eax,%eax
jle    11d6 <main+0xb6>
mov    %r13d,%ebx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <scanf@plt>
add    0x14(%rsp),%ebp
test   %r13d,%r13d
mov    0x10(%rsp),%eax
cmovs  %eax,%r13d
cmp    $0xd2,%ebp
cmovl  %ebx,%r13d
cmpb   $0x54,0xb(%rsp)
jne    1180 <main+0x60>
lea    0x1(%rax),%ecx
cmp    $0x8,%eax
mov    $0x1,%eax
cmove  %eax,%ecx
mov    %ecx,0x10(%rsp)
jmp    1180 <main+0x60>
lea    0xe2c(%rip),%rdi
mov    %r13d,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"%d %c\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
store i32 0, i32* %1
store i32 0, i32* %4
store i32 -1, i32* %5
%8 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%9 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
br label %10
10: ; preds = %39, %0
%11 = load i32, i32* %3
%12 = add nsw i32 %11, -1
store i32 %12, i32* %3
%13 = icmp sgt i32 %11, 0
br i1 %13, label %14, label %40
14: ; preds = %10
%15 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %6, i8* %7)
%16 = load i32, i32* %6
%17 = load i32, i32* %4
%18 = add nsw i32 %17, %16
store i32 %18, i32* %4
%19 = load i32, i32* %4
%20 = icmp sge i32 %19, 210
br i1 %20, label %21, label %26
21: ; preds = %14
%22 = load i32, i32* %5
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = load i32, i32* %2
store i32 %25, i32* %5
br label %26
26: ; preds = %24, %21, %14
%27 = load i8, i8* %7
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 84
br i1 %29, label %30, label %39
30: ; preds = %26
%31 = load i32, i32* %2
%32 = icmp eq i32 %31, 8
br i1 %32, label %33, label %34
33: ; preds = %30
br label %37
34: ; preds = %30
%35 = load i32, i32* %2
%36 = add nsw i32 %35, 1
br label %37
37: ; preds = %34, %33
%38 = phi i32 [ 1, %33 ], [ %36, %34 ]
store i32 %38, i32* %2
br label %39
39: ; preds = %37, %26
br label %10
40: ; preds = %10
%41 = load i32, i32* %5
%42 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %41)
%43 = load i32, i32* %1
ret i32 %43
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"%d %c\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%8 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %2
%10 = add nsw i32 %9, -1
store i32 %10, i32* %2
%11 = icmp sgt i32 %9, 0
br i1 %11, label %12, label %35
12: ; preds = %0
%13 = bitcast i32* %3 to i8*
br label %14
14: ; preds = %12, %31
%15 = phi i32 [ -1, %12 ], [ %24, %31 ]
%16 = phi i32 [ 0, %12 ], [ %19, %31 ]
%17 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %3, i8* %4)
%18 = load i32, i32* %3
%19 = add nsw i32 %18, %16
%20 = icmp sgt i32 %19, 209
%21 = icmp slt i32 %15, 0
%22 = select i1 %20, i1 %21, i1 false
%23 = load i32, i32* %1
%24 = select i1 %22, i32 %23, i32 %15
%25 = load i8, i8* %4
%26 = icmp eq i8 %25, 84
br i1 %26, label %27, label %31
27: ; preds = %14
%28 = icmp eq i32 %23, 8
%29 = add nsw i32 %23, 1
%30 = select i1 %28, i32 1, i32 %29
store i32 %30, i32* %1
br label %31
31: ; preds = %27, %14
%32 = load i32, i32* %2
%33 = add nsw i32 %32, -1
store i32 %33, i32* %2
%34 = icmp sgt i32 %32, 0
br i1 %34, label %14, label %35
35: ; preds = %31, %0
%36 = phi i32 [ -1, %0 ], [ %24, %31 ]
%37 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %36)
ret i32 0
}