L=int(input()) N=int(input()) W = input().split() W.sort(key=int) for i in range(N): if L >= int(W[i]): L -= int(W[i]) if N == i-1: print(i+1) break else: print(i) break