def data1(m,x):
lenth=len(x)
res=0
for i in range(lenth):
res+=int(list1.index(x[i]))*m**(lenth-1-i)
return res
def data2(n,x):
re=[]
if x==0:
return 0
else:
while x!=0:
x,res=divmod(x,n)
re.append(str(list1[res]))
return ''.join(re[::-1])
while True:
try:
list1=['0','1','2','3','4','5','6','7','8','9',
'A','B','C','D','E','F',
'G','H','I','J','K','L',
'M','N','O','P','Q','R',
'S','T','U','V','W','X',
'Y','Z']
m,n=map(int,input().strip().split(' '))
x=list(input().strip())
#print(data1(m,x))
result=data2(n,data1(m,x))
print(result)
except:
break