#include <iostream>
using namespace std;
int main()
{
unsigned long long int n, b, c;
cin >> n >> b >> c;
unsigned long long int zecimal=0, z=1;
while (n)
{
zecimal=zecimal+(n%10)*z;
z=z*b; n=n/10;
}
z=1; unsigned long long int num=0;
while (zecimal)
{
num=num+(zecimal%c)*z;
z=z*10; zecimal=zecimal/c;
}
cout << num;
}