n, k = input().split() k = int(k) ans = "" for b in n: b = ord(b) - ord("0") ans += str(k % b) k //= b ans = ans[::-1] print(int(ans))