L = int(input()) N = int(input()) W = list(map(int,input().split())) W.sort() length = 0 i = 0 cnt=0 while L>=(length+W[i]): length += W[i] cnt += 1 i += 1 if i>=N: break print(cnt)