L = int(input()) N = int(input()) block_list = list(map(int,input().split())) block_list.sort() block_count = 0 block_wide = 0 for i in block_list: block_wide += i if block_wide > L: break block_count += 1 print(block_count)