{-# LANGUAGE BangPatterns #-}
import Data.Array.Unboxed
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import qualified Data.IntMap as M
readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
type Sym = Array Int Int
main = do
  [n,k] <- map read . words <$> getLine
  a <-  getIntList
  let a' = listArray (1,n) a
  print $ solve n k a' ! 1

dot :: Int -> Sym -> Sym -> Sym
dot n s t = listArray (1,n) $ map (\i ->s ! (t ! 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