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