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