N, K = map(int, input().split()) K -= 1 ans = "" for c in str(N)[::-1]: n = int(c) ans += str(K % (n + 1)) K //= n + 1 ans = ans[::-1].lstrip('0') print(ans if len(ans) else 0)