l = int(input()) n = int(input()) w = list(map(int, input().split())) w = sorted(w) count = 0 for box in w : if box <= l : l = l - box count += 1 print (count)