#include #include #include using namespace std ; vector digs ; const int INF = 1000000000 ; int b, p ; int main() { cin >> b >> p ; vector cur0, cur1, nxt0, nxt1 ; cur0.push_back(0) ; cur1.push_back(INF) ; vector x(p) ; for (auto &v: x) cin >> v ; reverse(x.begin(), x.end()) ; for (auto v: x) { nxt0.clear() ; nxt1.clear() ; int nxt0sz = max(cur0.size(), cur1.size()) ; int nxt1sz = max(cur0.size() + b - v, cur1.size() + b - v - 1) ; nxt0.resize(nxt0sz, INF) ; nxt1.resize(nxt1sz, INF) ; int both = min(cur0.size(), cur1.size()) - 1 ; if (both < 0) both = 0 ; nxt1[b - v] = cur1[0] ; for (int j=0; j