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