{-# OPTIONS_GHC -O #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ViewPatterns #-}

import Control.Monad
import Control.Monad.ST
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as M
import qualified Data.Set as S

sol :: Int -> B.ByteString -> [(a, [Int])] -> B.ByteString
sol n s (idx:idxs) =
    if sz < n
        then sol (n-sz) s idxs
        else S.elemAt (n-1) sets
    where
        sz = S.size sets
        sets = foldl' (\set s -> S.insert s set) S.empty ss
        ss = concatMap ps $ snd idx
        ps i = drop 1 $ B.inits $ B.drop i s

main = do
    s <- B.getLine
    n <- readLn
    let idx = M.toList $ foldl' (\m (c,i) -> M.insertWith (++) c [i] m) M.empty $ zip (B.unpack s) [0..]
    putStrLn $ B.unpack $ sol n s idx
