(
  defn calc_pow [i bs x]
  (reduce #(if (> % %2) % %2) (filter #(< % x)(map #(Math/pow i %) (map #(+ % 1)(range bs)))))
)
(
  defn calc [bs x]
  (map #(calc_pow % bs x) (map #(+ % 1)(range bs)))
)
(def x (read))
(println (reduce #(if (> % %2) % %2))(calc x x))