L = gets.to_i N = gets.to_i ws = gets.split.map(&:to_i).sort len = 0 cnt = 0 while len < L len += ws.shift.to_i cnt += 1 end cnt -= 1 if len != L puts cnt