def max(a,b); a > b ? a : b; end
def min(a,b); a < b ? a : b; end
N, K = gets.split.map(&:to_i)
P = gets.split.map(&:to_i).tap{|array| array.unshift(0) }
C = gets.split.map(&:to_i).tap{|array| array.unshift(0) }

ans = (1 .. N).map do |s|
  dp = Array.new(N + 1, 0)
  smax = Array.new(N + 1, 0)

  (1 .. N).inject(s) do |u, i|
    break u if i > K
    v = P[u]
    dp[i] = dp[i - 1] + C[v]
    smax[i] = max(smax[i - 1], dp[i])
    v
  end
  if K < N || dp[N] <= 0
    smax[K % N]
  else
    k = K / N
    d = K % N
    max(dp[N] * k + smax[d], dp[N] * (k - 1) + smax[N])
  end
end.max

puts ans