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