data = int(input()) num = int(input()) block = input().split(' ') int_block = [int(s) for s in block] list.sort(int_block) count = 0 sum = 0 for i in range(num): sum += int_block[i] if sum > data: break count += 1 print(count)