l = int(input()) input() ans = 0 for v in sorted(map(int, input().split())): if l >= v: ans += 1 l -= v print(ans)