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