-- https://atcoder.jp/contests/abc175/submissions/15989458 の改変
import           Control.Monad
import           Data.Array
import           Data.List
getIntLine = map read . words <$> getLine
main = do
  [n,k] <- getIntLine
  p <- listArray (1,n) <$> getIntLine
  c <- listArray (1,n) <$> getIntLine
  let acc i= tail $ scanl' (+) 0 $ map ((c !).(p !)) $ takeWhile (/= i) (tail $ iterate (p !) i) ++ [i]
      ans i =
        if val > 0
          then
            if rem /= 0
              then num * val + maximum (take rem list)
              else (num-1) * val + maximum list
          else maximum list
        where list = acc i
              val = last list
              len = length list
              num = k `div` len
              rem = k `mod` len
  print $ maximum $ map ans [1..n]
