let rec iter a b f = if a > b then [] else let v = f a in v :: iter (a+1) b f
let () =
  Scanf.scanf "%s %d" @@ fun s k ->
  let n = String.length s in
  iter 1 5 (fun l -> iter 0 (n-l) (fun i -> String.sub s i l))
  |> List.concat |> List.sort_uniq compare
  |> fun xs -> print_endline (List.nth xs (k-1))