#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 *, unsigned int);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main() {
  unsigned int total = 0;
  int n;
  int t;
  scanf("%d %d", &n, &t);
  int nn;
  nn = n;
  int c;
  for (int c_i = 0; c_i < t; c_i++) {
    scanf("%d", &c);
    if (5 > n) {
      total += (nn - n);
      n = nn;
    }
    n -= c;
  }
  printf("%u\n", total);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xec3(%rip),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11b0 <main+0x90>
lea    0xe97(%rip),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    $0x5,%eax
cmp    -0xc(%rbp),%eax
jle    1197 <main+0x77>
mov    -0x14(%rbp),%eax
sub    -0xc(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0xc(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1159 <main+0x39>
mov    -0x8(%rbp),%esi
lea    0xe4c(%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   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xecb(%rip),%rdi
xor    %ebx,%ebx
lea    0xc(%rsp),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1040 <scanf@plt>
cmpl   $0x0,0x10(%rsp)
jle    11a6 <main+0x86>
mov    0xc(%rsp),%r12d
lea    0xea8(%rip),%r14
lea    0x14(%rsp),%r15
xor    %ebp,%ebp
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0xc(%rsp),%eax
lea    (%r12,%r13,1),%ebx
sub    %eax,%ebx
cmp    $0x5,%eax
cmovl  %r12d,%eax
cmovge %r13d,%ebx
sub    0x14(%rsp),%eax
mov    %eax,0xc(%rsp)
add    $0x1,%ebp
mov    %ebx,%r13d
cmp    0x10(%rsp),%ebp
jl     1170 <main+0x50>
lea    0xe59(%rip),%rdi
mov    %ebx,%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 = [6 x i8] c"%d %d\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%u\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 i32
store i32 0, i32* %1
store i32 0, i32* %2
%8 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %3, i32* %4)
%9 = load i32, i32* %3
store i32 %9, i32* %5
store i32 0, i32* %7
br label %10
10: ; preds = %29, %0
%11 = load i32, i32* %7
%12 = load i32, i32* %4
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %32
14: ; preds = %10
%15 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%16 = load i32, i32* %3
%17 = icmp sgt i32 5, %16
br i1 %17, label %18, label %25
18: ; preds = %14
%19 = load i32, i32* %5
%20 = load i32, i32* %3
%21 = sub nsw i32 %19, %20
%22 = load i32, i32* %2
%23 = add i32 %22, %21
store i32 %23, i32* %2
%24 = load i32, i32* %5
store i32 %24, i32* %3
br label %25
25: ; preds = %18, %14
%26 = load i32, i32* %6
%27 = load i32, i32* %3
%28 = sub nsw i32 %27, %26
store i32 %28, i32* %3
br label %29
29: ; preds = %25
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
br label %10
32: ; preds = %10
%33 = load i32, i32* %2
%34 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %33)
ret i32 0
}

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