l = int(input()) n = int(input()) w = [int(i) for i in input().split()] w.sort() ans = 0 i = 0 while l > 0: l -= w[i] ans += 1 i += 1 print(ans - 1)