L = int(input()) N = int(input()) W = sorted(map(int, input().split())) cnt = 0 for i in range(N): L -= W[i] if L < 0: break cnt += 1 print(cnt)