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