l = int(input()) n = int(input()) w = [int(x) for x in input().split(" ")] sorted_w = sorted(w) count = 0 sum = 0 for i in range(n): sum += sorted_w[i] count += 1 if sum > l: count -= 1 break print(count)