x = int(input()) y = int(input()) index = 0 for b in sorted([int(a) for a in input().split()]): x -= b if x >= 0 : index += 1 else : break print(index)