import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import qualified Data.Vector.Unboxed as VU
import qualified Data.IntSet as IS

main :: IO ()
main = do
  [n, k] <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  as <- VU.map pred . unsafeTextToVectorInt <$> T.getLine :: IO (VU.Vector Int)
  let
    rho = VU.unfoldr next (Just 0, IS.empty) :: VU.Vector Int
      where
        next (Just i, s) | IS.member i s = Just (i, (Nothing, s))
                         | otherwise     = Just (i, (Just (as VU.! i), IS.insert i s))
        next _                           = Nothing
    start = until ((== VU.last rho) . (rho VU.!)) succ 0 :: Int
    period = pred (VU.length rho) - start
  print .succ $ if k < start then rho VU.! k else rho VU.! (start + (k - start) `mod` period)

unsafeTextToVectorInt :: T.Text -> VU.Vector Int
unsafeTextToVectorInt = VU.unfoldr next
  where
    next :: T.Text -> Maybe (Int, T.Text)
    next s | T.null s  = Nothing
           | otherwise = Just . either undefined (T.stripStart <$>) . T.signed T.decimal $ s
{-# INLINE unsafeTextToVectorInt #-}

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}
