L = int(input()) N = int(input()) block_list = [int(x) for x in input().split(" ")] block_list.sort() count = 0 for length in block_list: L -= length if L >= 0: count += 1 else: break print(count)