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)

k.times do
  ind = p_arr[ind] - 1
  score += c_arr[ind]
  score_arr << score
end
puts score_arr.max
