import           Data.List
import           Control.Applicative
import           Control.Monad

unique []  = []
unique [x] = [x]
unique (x1 : x2 : rest) | x1 == x2  = unique $ x1 : rest
                        | otherwise = x1 : unique (x2 : rest)

gs' :: Char -> [String] -> [String]
gs' o acc = [o] : map (\ac -> o : ac) acc

gs :: String -> [String]
gs [] = []
gs xs = foldr gs' [] xs

subs :: Char -> String -> [String]
subs _ [] = []
subs o xs@(x : rs) | o == x    = sort (gs xs ++ subs o rs)
                   | otherwise = subs o rs

main = do
  target <- getLine
  n      <- readLn
  putStrLn $ last $ take n $ unique $ foldl (\acc o -> acc ++ subs o target)
                                         []
                                         ['a' .. 'z']
