L = int(input()) N = int(input) W = list(map(int, input().split())) W.sort() cap = 0 ans = 0 for i in range(N): cap += W[i] if cap > L: break else: ans += 1 print(ans)