l=input() input() w=sorted(map(int,raw_input().split())) s = 0; i = 0 while s+w[i] <= l: s += w[i] i += 1 print i