#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 main() {
  char buffer[6];
  int limit = 0, events = 0, current = 0, next = 0, rejects = 0;
  scanf("%d %d", &limit, &events);
  while (events--) {
    scanf("%s %d", buffer, &next);
    if (buffer[0] == 'e') {
      if (current + next > limit)
        rejects++;
      else
        current += next;
    } else {
      current -= next;
    }
  }
  printf("%d\n", rejects);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
lea    0xea7(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
je     11da <main+0xba>
lea    -0xa(%rbp),%rsi
lea    0xe7f(%rip),%rdi
lea    -0x1c(%rbp),%rdx
mov    $0x0,%al
call   1040 <scanf@plt>
movsbl -0xa(%rbp),%eax
cmp    $0x65,%eax
jne    11ca <main+0xaa>
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    11bc <main+0x9c>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11c5 <main+0xa5>
mov    -0x1c(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    11d5 <main+0xb5>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
jmp    1168 <main+0x48>
mov    -0x20(%rbp),%esi
lea    0xe28(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
movl   $0x0,0x14(%rsp)
movl   $0x0,0xc(%rsp)
movl   $0x0,0x10(%rsp)
lea    0xeb5(%rip),%rdi
xor    %ebx,%ebx
lea    0x14(%rsp),%rsi
lea    0xc(%rsp),%rdx
xor    %eax,%eax
call   1040 <scanf@plt>
subl   $0x1,0xc(%rsp)
jb     11be <main+0x9e>
lea    0xe9a(%rip),%r14
lea    0x1a(%rsp),%r15
lea    0x10(%rsp),%r12
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    1189 <main+0x69>
nopl   0x0(%rax)
sub    %eax,%ebp
subl   $0x1,0xc(%rsp)
jb     11be <main+0x9e>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <scanf@plt>
cmpb   $0x65,0x1a(%rsp)
mov    0x10(%rsp),%eax
jne    1180 <main+0x60>
add    %ebp,%eax
xor    %ecx,%ecx
cmp    0x14(%rsp),%eax
setg   %dl
jg     11b3 <main+0x93>
mov    %eax,%ebp
mov    %dl,%cl
add    %ecx,%ebx
subl   $0x1,0xc(%rsp)
jae    1189 <main+0x69>
lea    0xe47(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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