l = int(input()) n = int(input()) W = sorted(map(int, input().split())) ans = 0 cnt = 0 for w in W: cnt += w if cnt > l: break ans += 1 print(ans)