import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, std.bitmanip; immutable long MOD = 10^^9 + 7; immutable long INF = 1L << 59; void main() { auto T = readln.chomp.to!int; auto N = readln.chomp.to!int; auto A = N.iota.map!(_ => readln.chomp.to!int).array; int cost(int mask) { return N.iota.filter!(i => (1 << i) & mask).map!(i => A[i]).sum; } int dfs(int mask) { if (mask == 0) { return 0; } int ret = 1 << 29; for(int nmask = mask; nmask > 0; nmask = (nmask-1) & mask) { if (cost(nmask) <= T) { ret = min(ret, dfs(mask ^ nmask) + 1); } } return ret; } dfs((1 << N) - 1).writeln; }