n=int(input()) m=int(input()) x=0 y=0 while True: y+=(n%(m**(x+1)))*(10**x) if n