let rec power ( * ) one m = function
  | 0 -> one
  | n when n mod 2 = 0 ->
      power ( * ) one (m * m) (n / 2)
  | n ->
      m * power ( * ) one m (n - 1)

let rec upper_bound l r p =
  if r <= 1 + l
  then l
  else let m = (l + r) / 2 in
       if p m 
       then upper_bound m r p
       else upper_bound l m p

let () = Scanf.scanf "%d\n" @@ fun x ->
  Array.init (int_of_float (sqrt @@ float_of_int x) - 1) (( + ) 2)
  |> Array.map (fun b ->
    power ( * ) 1 b @@ upper_bound 2 9 @@ fun p -> power ( * ) 1 b p <= x)
  |> Array.fold_left max 1
  |> Printf.printf "%d\n"

