l = int(input()) n = int(input()) ws = list(map(int, input().split())) min = 10000 remain = l count = 0 ws.sort() for i in ws: l -= i if l >= 0: count += 1 else: break print(count)