total = 0 ans = 0 L = int(input()) N = input() W = list(map(int, input().split())) W.sort() for i in W: total += i ans += 1 if L < total: break if total <= L: print(ans) else: print(ans - 1)