L = int(input()) N = int(input()) W = sorted(list(map(int,input().split()))) sum_temp = 0 sum_num = 0 for i in W: sum_temp += i if not sum_temp >= L: sum_num += 1 elif sum_temp >= L: break print(sum_num)