#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 */
char getchar();
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ solve(int, int, char *);
int main() {
  int k, n;
  scanf("%d\n", &k);
  scanf("%d\n", &n);
  char ds[n];
  int i;
  for (i = 0; i < n; ++i) {
    ds[i] = getchar() - '0';
  }
  printf("%ld\n", solve(k, n, ds));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    %rdi,-0x38(%rbp)
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x38(%rbp),%rdi
lea    -0xc(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0xc(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d3 <main+0x93>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,%cl
mov    -0x30(%rbp),%rax
movsbl %cl,%ecx
sub    $0x30,%ecx
mov    %cl,%dl
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    119d <main+0x5d>
mov    -0x30(%rbp),%rdx
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <solve@plt>
mov    %eax,%esi
lea    0xe19(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xeaf(%rip),%rbx
lea    -0x20(%rbp),%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
lea    -0x1c(%rbp),%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
mov    %rsp,%r14
mov    -0x1c(%rbp),%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    -0x1c(%rbp),%esi
test   %esi,%esi
jle    11aa <main+0x6a>
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <getchar@plt>
add    $0xd0,%al
mov    %al,(%r15,%rbx,1)
add    $0x1,%rbx
movslq -0x1c(%rbp),%rsi
cmp    %rsi,%rbx
jl     1190 <main+0x50>
mov    -0x20(%rbp),%edi
mov    %r15,%rdx
call   1030 <solve@plt>
lea    0xe48(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %r14,%rsp
xor    %eax,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [5 x i8] c"%ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %2)
%8 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %3)
%9 = load i32, i32* %3
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %4
%12 = alloca i8, i64 %10
store i64 %10, i64* %5
store i32 0, i32* %6
br label %13
13: ; preds = %25, %0
%14 = load i32, i32* %6
%15 = load i32, i32* %3
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %28
17: ; preds = %13
%18 = call signext i8 (...) @getchar()
%19 = sext i8 %18 to i32
%20 = sub nsw i32 %19, 48
%21 = trunc i32 %20 to i8
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %12, i64 %23
store i8 %21, i8* %24
br label %25
25: ; preds = %17
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
br label %13
28: ; preds = %13
%29 = load i32, i32* %2
%30 = load i32, i32* %3
%31 = call i32 @solve(i32 %29, i32 %30, i8* %12)
%32 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %31)
%33 = load i8*, i8** %4
%34 = load i32, i32* %1
ret i32 %34
}

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