#include namespace { #pragma GCC diagnostic ignored "-Wunused-function" #include #pragma GCC diagnostic warning "-Wunused-function" using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; using ull = unsigned long long; constexpr int M = 9 * 18; ull dp[100001][M]; } int main() { ios::sync_with_stdio(false); cin.tie(0); ull n, k; cin >> n >> k; if (n >= M) { cout << k << '\n'; return 0; } constexpr ull INF = 1002003004005006007; rep(r, M) dp[0][r] = 1; rep(i, 100000) { rep(r, M) { dp[i+1][r] += dp[i][r]; if (r + 10 < M) dp[i+1][r+10] -= dp[i][r]; } rep(r, M - 1) dp[i+1][r+1] += dp[i+1][r]; rep(r, M) chmin(dp[i+1][r], INF); } string ans; for (int i = 100000; i > 0; i--) { int v = 0; while (dp[i-1][n] <= k) { k -= dp[i-1][n]; n--; v++; } ans += '0' + v; } reverse(all(ans)); while (ans.back() == '0') ans.pop_back(); reverse(all(ans)); cout << ans << '\n'; }