l = int(input()) input() ans = [] for j in sorted(map(int, readline().split())): if sum(ans + [j]) > l: break ans.append(j) print(len(ans))