def main(): """ main """ L = int(input()) N = int(input()) WS = sorted(list(map(int, input().split()))) dp = [0 for _ in range(N+1)] cnt = 0 total = 0 for i in WS: if total+i <= L: total += i cnt += 1 else: break print(cnt) main()