l = int(input()) n = int(input()) w = list(map(int,input().split())) w.sort() total = 0 i = 0 while (total+w[i]) < l: total += w[i] i += 1 print(i)