L = int(input()) N = int(input()) w_list = list(map(int, input().split())) w_list_sorted = sorted(w_list) counter = 0 s = 0 for w in w_list_sorted: s+=w if s>L: break counter+=1 print(counter)