L = int(input()) N = int(input()) W = list(map(int,input().split())) for i in range(N): for j in range(N): if W[j] >= W[i]: tmp = W[j] W[j] = W[i] W[i] = tmp sum_wide = 0 ans = 0 while True: if sum_wide + W[ans] > L: break sum_wide += W[ans] ans += 1 print(ans)