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 num = 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
  if log (float_of_int k) < (float_of_int num) *. log (float_of_int i)
  then i
  else f (tail s) (k - pow i num)

let () = let ans = scanf "%s\n%d\n" f in
  printf "%d\n" ans