L = input() N = input() e = map(int, raw_input().split()) e.sort count=0 while L>=0 : L = L - e[j] count = count + 1 else: print count - 1