module Main where
import qualified Control.Monad as C
import qualified Data.Char as C
import qualified Data.List as L
import qualified Data.Map as M
import qualified Data.Array as A

int = read :: String -> Int
getWord :: IO String
getWord = do
  c <- getChar
  if C.isSpace c
  then
    return []
  else do
    ws <- getWord
    return (c:ws)
getInt = fmap int getWord
replace pred a = map (\x -> if pred x then a else x)

main = interact $ printer . solver . parser
parser = words
printer = id

solver [s,k] = s4 !! (int k - 1)
  where
    s1 = L.tails s :: [String]
    s2 = L.sort s1 :: [String]
    s3 = concatMap inits s2 :: [String]
    s4 = myfil "" s3 :: [String]
    
myfil t [] = []
myfil t (a:as) = 
      if t < a
      then a:myfil a as
      else myfil t as

inits :: [a] -> [[a]]
inits [] = []
inits (x:xs) = inits' (x:) xs

inits' :: ([a]->[a]) -> [a] -> [[a]]
inits' pre [] = [pre []]
inits' pre (x:xs) = (pre []) : inits' (pre . (x:)) xs
