import qualified Data.Map as M
import Data.Maybe
type Sym a = M.Map a a

main = do
  [n,k] <- map read . words <$> getLine
  a <- map read . words <$> getLine
  let a' = zip [0..n] (map (\t -> t-1) a)
  print $ 1 + (Data.Maybe.fromMaybe 0 $ M.lookup 0 $ solve k (M.fromList a') )

(.^) :: (Ord a) => a -> Sym a -> a
x .^ g = Data.Maybe.fromMaybe x (M.lookup x g) -- if x `notElem` supp (P g), then x is not moved

dot ::(Ord a) => Sym a -> Sym a -> Sym a
dot sigma tau = M.fromList [(x,x .^ sigma .^ tau) | x <- M.keys (sigma `M.union` tau)]

solve :: Int -> Sym Int-> Sym Int
solve k sigma
  | k == 1 = sigma
  | even k = s `dot` s
  | otherwise  = sigma `dot` solve (k-1) sigma
    where s = solve (k `div` 2) sigma