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