max_num = int(input()) num = int(input()) blocks = input().split() blocks_size = [int(i) for i in blocks] blocks_size.sort() count = 0 blocks_sum = 0 for i in blocks_size: blocks_sum += i if blocks_sum <= max_num: count += 1 else: break print(count)