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