n, k = gets.split(" ").map(&:to_i)
p_arr = gets.split(" ").map(&:to_i)
c_arr = gets.split(" ").map(&:to_i)

score = 0
score_arr = []

max_ind = c_arr.index(c_arr.max)
ind = p_arr.index(max_ind + 1)

max_score = -1_000_000_000
k.times do
  ind = p_arr[ind] - 1
  score += c_arr[ind]
  max_score = score if max_score < score
end
puts max_score
