l = int(input()) n = int(input()) w = list(sorted(map(int, input().split()))) summation = 0 for i, v in enumerate(w): summation += v if summation > l: break print(i)