# coding: utf-8 # Your code here! all_length = int(input()) num = int(input()) length_arr = [int(x) for x in input().split()] length_arr.sort() ct = 0 for i in range(len(length_arr)): if all_length - length_arr[i] >= 0: all_length -= length_arr[i] ct += 1 else: break print(ct)