L = int(input()) N = int(input()) W_list = [int(x) for x in input().split()] max_num = 0 W_list_ascending = sorted(W_list) while L > 0: if L > W_list_ascending[0]: L = L - W_list_ascending[0] W_list_ascending.pop(0) max_num = max_num + 1 else: break print(max_num)