import itertools L = int(input()) N = int(input()) W = list(map(int, input().split())) all_combinations = [] for r in reversed(range(N)): combinations_object = itertools.combinations(W, r) combinations_list = list(combinations_object) all_combinations += combinations_list for comb in all_combinations: if sum(comb) <= L: print(len(comb)) break