module StringSet = Set.Make (struct
  type t = string
  let compare = String.compare
end)

let substrs s =
  let rec substr_all from len =
    if from + len > String.length s then []
    else String.sub s from len :: substr_all from (succ len) in
  let rec substr_from from =
    if from = String.length s then []
    else
      substr_all from 1 @ substr_from (succ from)
  in
  substr_from 0

let nth_substr s n =
  let list = List.fold_left (fun s e -> StringSet.add e s) StringSet.empty @@ substrs s
  |> StringSet.elements
  |> List.sort String.compare in
  List.nth list @@ pred n

let main () =
  let s, n = Scanf.scanf "%s %d" (fun s n -> (s, n)) in
  nth_substr s n
  |> print_string

let () = main ()
