(* log(n) *)
let rec is_divisible n m c =
  if c = 0 then
    true
  else
    if n mod m = 0 then
      is_divisible (n / m) m (c - 1)
    else
      false

(* O(√p * log(p)) *)
let solve n p =
  if n = 1 then
    p
  else (* n >= 2 *)
    let m = int_of_float (floor (sqrt (float_of_int p))) in
    let rec loop g =
      if is_divisible p g n then
        g
      else
        loop (g - 1)
    in
      loop m (* n >= 2 では g <= m (∵ 指数関数の単調増加性より) *)

let _ = Scanf.scanf "%d %d" (fun n p -> solve n p |> string_of_int |> print_endline)