a=int(input()) b=int(input()) x=1 y=0 while True: y+=((b/(a**x))%a)*(10**(x-1)) b-=(b/(a**x)%a)*(a**(x-1)) x+=1 if a**x>b: break print(y)