l = int(input()) n = int(input()) w = list(map(int,input().split())) w.sort() count = 0 for i in range(n): if l-w[i] <= 0: break else: count += 1 l -= w[i] print(count)