L = int(input()) N = int(input()) W = [int(i) for i in input().split()] W.sort() while sum(W) > L: W.pop(-1) print(len(W))