N, K = input().split() N = N[::-1] K = int(K) - 1 ans = 0 for i, n in enumerate(N): n = int(n) ans += K % (n + 1) * 10 ** i K //= n + 1 print(ans)