l = int(input()) n = int(input()) w = sorted(list(map(int, input().split()))) for elem in w: l -= elem if l >= 0: n -= 1 else: break print(len(w) - n)