let N,K = stdin.ReadLine().Split() |> fun x -> int x.[0], int64 x.[1]
let lists = stdin.ReadLine().Split() |> Array.map int |> Array.zip <| (stdin.ReadLine().Split() |> Array.map int64)

let calcScore =
    let rec calcScoreInner start score times results = 
        if times > K then results
        else 
            let p,_ = lists.[start]
            let _,c = lists.[p-1]
            let sumScore = score + c
            calcScoreInner (p-1) sumScore (times+1L) results @ [sumScore]
    [for i=0 to N-1 do (calcScoreInner i 0L 0L []) |> List.max] |> List.max

calcScore |> printfn "%d"