l = gets.to_i n = gets.to_i ww = gets.split(' ').map(&:to_i).sort ans = 0 i = 0 while l >= 0 do l -= ww[i] ans += 1 i += 1 end puts ans - 1