#include using namespace std; int ans[100010]; long long dp[100010][10][170]; int main() { long long n, m; cin >> n >> m; n = min(n, 162ll); m++; dp[1][0][0] = 1; int t = 1; for (int i = 1; i <= 100000; i++) { 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) { dp[i + 1][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 += dp[i + 1][j][k]; if (sum >= m) { break; } } if (sum >= m) { break; } } if (sum >= m) { t = i + 1; break; } } for (int i = 1; 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]; } } } int cur = n, idx = 0; long long x = m; for (int i = t; i >= 2; i--) { for (int j = 0; j <= 9; j++) { if (dp[i][j][cur] < x) { x -= dp[i][j][cur]; } else { ans[++idx] = j; cur -= j; break; } } } for (int i = 1; i <= idx; i++) { cout << ans[i]; } return 0; }