l = int(input()) input() ans = 0 now = 0 for w in sorted(map(int, input().split())): now += w if now > l: break else: ans += 1 print(ans)