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