#include #include using namespace std; int main() { long long n, m; cin >> n >> m; n = min(n, 162LL); m++; vector>> dp; dp.push_back(vector>(10, vector(n + 1, 0))); dp[0][0][0] = 1; int t = 0; for (int i = 0; i < 100000; i++) { vector> nxt(10, vector(n + 1, 0)); for (int j = 0; j <= 9; j++) { for (int k = 0; k <= n; k++) { if (!dp[i][j][k]) continue; for (int l = 0; l <= 9; l++) { if (k + l <= n) { nxt[l][k + l] += dp[i][j][k]; } } } } long long sum = 0; for (int j = 0; j <= 9; j++) { for (int k = 0; k <= n; k++) { sum += nxt[j][k]; if (sum >= m) break; } if (sum >= m) break; } dp.push_back(move(nxt)); t = i + 1; if (sum >= m) break; } for (int i = 0; i <= t; i++) { for (int j = 0; j <= 9; j++) { for (int k = 1; k <= n; k++) { dp[i][j][k] += dp[i][j][k - 1]; } } } vector ans; int cur = n; long long x = m; for (int i = t; i >= 1; i--) { for (int j = 0; j <= 9; j++) { if (dp[i][j][cur] < x) { x -= dp[i][j][cur]; } else { ans.push_back(j); cur -= j; break; } } } for (int i = 0; i < ans.size(); i++) { cout << ans[i]; } return 0; }