l = int(input()) n = int(input()) w = sorted(map(int, input().split())) while sum(w) > l: w.pop() print(len(w))