open Scanf
open Printf

let tail s = String.sub s 1 (String.length s - 1)
let head s = int_of_string (String.sub s 0 1)

let n = float_of_int @@ 5000 * 10000 * 10000 * 10000

let pow i n = if i = 1
  then 1
  else begin
    let rec pow' k n = if n = 1 then k else pow' (k * i) (n - 1)
    in pow' i n
  end

let rec f s k = let i = head s in
  let a = log @@ float_of_int i in
  if k < n *. a
  then i
  else f (tail s) (k +. log (1. -. exp (n *. a -. k)))

let () = let ans = scanf "%s\n%d\n" (fun s k -> f s (log @@ float_of_int k)) in
  printf "%d\n" ans