L = int(input()) N = int(input()) W = list(map(int, input().split())) for i in range(N): minj = i for j in range(i,N): if W[j] < W[minj]: minj = j if i != minj: W[i], W[minj] = W[minj], W[i] s = 0 count = 0 for i in range(N): if s + W[i] <= L: s += W[i] count += 1 else: break print(count)