def quick_sort(list): if len(list) < 1: return list pivot = list[0] left = [] right = [] for i in range(1, len(list)): if list[i] < pivot: left.append(list[i]) else: right.append(list[i]) left = quick_sort(left) right = quick_sort(right) foo = [pivot] return left + foo + right def list_convert_int(list): converted_list = [] for str in list: converted_list.append(int(str)) return converted_list def main(): L = int(input()) N = int(input()) width_list = input().split() sum_width = 0 count = 0 list = list_convert_int(width_list) sorted_width_list = quick_sort(list) for i in sorted_width_list: width = int (i) if sum_width + width > L: break else: sum_width += width count += 1 print(count) if __name__ == '__main__': main()