import Data.Array
type Sym = Array Int Int

main = do
  [n,k] <- map read . words <$> getLine
  a <-  map read . words <$> getLine
  let a' = array (1,n) $ zip [1..n] a
  print $ solve n k a' ! 1

dot :: Int -> Sym -> Sym -> Sym
dot n s t = array (1,n) [(i,s ! (t ! i)) | i <- [1..n]]

solve :: Int -> Int -> Sym -> Sym
solve n k s
  | k == 1 = s
  | odd k = s <> solve n (k-1) s
  | otherwise = t <> t
    where (<>) = dot n
          t = solve n (k `div` 2) s
