def baseN(num, b):
return ((num == 0) and "0") or (baseN(num // b, b).lstrip("0") + "0123456789abcdefghijklmnopqrstuvwxyz"[num % b])
while True:
try:
a,b=map(int,input().split())
c=input()
val=int(c,a)
print(baseN(val,b))
except:
break
#M进制--10进制--N进制 voc=['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'] def f(x,n): #10进制转换为n进制,n<=36 p,q=x,0 a=[] while p!=0: p,q=p//n,p%n a.append(voc[q]) return ''.join(a[::-1]) while 1: try: m,n=list(map(int,input().split())) x=int(input(),m) #m进制转换为10进制 print(f(x,n)) except: break