l = int(input()) n = int(input()) w = list(map(int, input().split())) w.sort() ans = 0 for num in w: l -= num if l < 0: break ans += 1 print(ans)