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