a = gets.to_i b = gets c = gets.split.sort n = 0 while a >0 do a -= c[n].to_i n += 1 end puts n -1