import sys from functools import lru_cache sys.setrecursionlimit(2000) def num2v(n): retval = [] if n == 0: retval.append(0) while n > 0: retval.append(n % 10) n //= 10 retval.reverse() return retval @lru_cache(None) def dp(digits, i=0, empatado=True, x=0): if i == len(digits): return 1 ans = 0 r = digits[i] if empatado else 9 for val in range(r + 1): new_empatado = empatado and val == r if x + val <= n: ans += dp(tuple(digits), i + 1, new_empatado, x + val) return ans def good(x): digits = num2v(x) dp.cache_clear() return dp(tuple(digits)) >= k def solve(l, r): while r - l > 1: mid = l + (r - l) // 2 if good(mid): r = mid else: l = mid return r n, k = map(int, input().split()) k += 1 n = min(n, 400) l, r = 0, 1 while not good(r): r *= 2 ans = solve(l, r) print(ans)