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