/*

?? 
?????????????????2???36?????????long?????????? 
???????????0?1?...?9?a?b?...?z????0?1?...?9?A?B?...?Z??
 
???? 
?????????????a?n?b?a?????n ?a?????b????a????n???b????? 
a?b???????2 ? a?b < 36?
 
???? 
???????????????????b?????????????????????0?1?...?9?A?B?...?Z??
 
???? 
15 Aab3 7
 
???? 
210306
 
?? 
??????????????? 
*/


int dec(char nf[100],int ii,int sysf)     //?????????????
{                                         //nf???????????nf?0??nf?ii??????sysf?????????
	int sum=0,exp=1;
	int k,j;
	for (k=ii;k>=0;k--)
	{
		if (ii!=k)  exp=exp*sysf;
		sum+=((int)nf[k])*exp;
	}
	return sum;
}


void trans(char outf[100],int pos,int decf,int sysf) //?????????????????????????????????????????
{  //outf????????????outf?99??outf?0????pos?????????????decf??????????sysf??????
	int rem,t;
	while((decf!=0)&&(pos>=0))
	{
	    rem=decf%sysf;   //rem???????????
	    decf=(int)(decf/sysf);   //decf??????????
	    if ((rem>=0)&&(rem<=9))   outf[pos]=rem+48;
	    else if ((rem>=10)&&(rem<=35))  outf[pos]=rem+55;
		pos--;
	}
	for (t=pos+1;t<=99;t++)     cout<<outf[t];
	cout<<endl;
}

int main()
{
	int a,b,i=0,k,temp;
	char n[100],c;
	char output[100];
	cin>>a;
	getchar();
	while (c=getchar(),c!=' ')
	{
		n[i]=c;
		i++;
	}
	i--;
	cin>>b;
	for (k=0;k<=i;k++)
	{
		if ((n[k]>='a')&&(n[k]<='z'))  n[k]-=87;
		else if ((n[k]>='A')&&(n[k]<='Z'))  n[k]-=55;
		else if ((n[k]>='0')&&(n[k]<='9'))  n[k]-=48;
	}
	temp=dec(n,i,a);
	if (temp==0)  cout<<"0"<<endl;
	else   trans(output,99,temp,b);
    return 0;
}