import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val N, K = sc.nextInt
  val P = Array.fill(N)(sc.nextInt)
  val C = Array.fill(N)(sc.nextLong)

  val over = K > N
  val n = if (over) N else K
  val memo = Array.fill(N, n)((0L, 0))

  for (i <- 0 until N; j <- 0 until n) {
    val prevScore = if (j == 0) 0 else memo(i)(j - 1)._1
    val pos = if (j == 0) P(i) - 1 else P(memo(i)(j - 1)._2) - 1
    memo(i)(j) = (prevScore + C(pos), pos)
  }

  val x = memo.map(_.map(_._1).toSeq).toSeq

  val z = if (over) {
    val a = K / N
    val b = K % N

    memo.map(x => {
      val c = x.map(_._1)
      c.last * a + c(b - 1)
    }).max
  } else memo.flatMap(_.map(_._1)).max

  println(z)
}
