Number systems#611

Number systems

1 second
128 megabytes
Medium

Chuck Norris counted to infinity. Twice.

(Internet folklore)

The young mathematician Vovochka is so diligent that he wrote out all positive integers in ascending order. In a fit of zeal, he converted all numbers in this sequence into the numeral system with base . Then, Vovochka crossed out every number in the sequence that can be written as the representation of some number in the numeral system with base .

Vovochka's diligence ran out, and he asked you, his friend and programmer, to find the -th number in the sequence that was not crossed out. Help the young mathematician Vovochka!

Input

You are given three numbers: , , and (1 \le n \le 10^7, 2 < c < b \le 36). In numeral systems with bases greater than , the lowercase Latin letters , , are used as digits in addition to , , .

Output

Print (in the decimal system) the -th non-crossed number of the sequence.

Examples

Example 1

Loading
Loading

Example 2

Loading
Loading