L = int(input()) N = int(input()) W = sorted(map(int, input().split())) # print(L, W) while sum(W) > L: W.pop() print(len(W))