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