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