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