l = int(input()) input() w = list(map(int, input().split())) w.sort() total = 0 cnt = 0 for wi in w: total += wi if total > l: break cnt += 1 print(cnt)