L = int(input()) N = int(input()) W = input().split() W.sort(key=int) l=0 i=0 for i in range(N): l += int(W[i]) i += 1 if l >= L: break print(i)