code
#include<iostream>
#define min(a,b)a>b?b:a
using namespace std;
int n, m, a[25502], b[100];
int main() {
ios::sync_with_stdio(false);
cin >> n >> m;
for (int i = 0, j; i < m; i++) {
cin >> j;
a[j] = 1;
}
for (int i = 1, j = 0; ; i++) {
if (a[i] == 1) {
b[j++] = i;
cout<<"b["<<j<<"]="<<b[j-1]<<'\n';
} else {
m = n;
for (int k = 0; k < j; k++) {
m = min(m, a[i - b[k]]);
cout<<"i="<<i<<" b["<<k<<"]="<<b[k]<<" i-b[k]="<<i-b[k]<<" a[i-b[k]]="<<a[i - b[k]]<<" m="<<m<<'\n';
}
if (++m > n) {
cout << i - 1;
break;
}
a[i] = m;
}
}
return 0;
}
ref