n = int(input()) m = int(input()) def ten_to_m(n,m): res = 0 cnt = 0 while n > 0: res += (n % m) * 10 ** cnt n = n // m cnt += 1 return res print(ten_to_m(m,n))