ソースコード
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef pair<P, int> PP;
//i桁でjが桁和になるものの個数
ll dp[1001][1001] = {};
void init() {
dp[0][0] = 1;
Rep(i, 1, 1001) {
rep(j, 1001) {
rep(k, 10) {
if (j - k >= 0) {
dp[i][j] += dp[i - 1][j - k];
}
}
}
}
}
string kth(int n,ll k){
int chk = 0;
rep(i, 1001) {
if (dp[i][n] > k) {
chk = i; break;
}
}
chk--;
ll d = k / dp[chk][n];
ll r = k % dp[chk][n];
char nex = '0' + d;
return nex + kth(n - d, r);
}
int main(){
init();
int n; ll k; cin >> n >> k;
int chk = 0;
rep(i, 1001) {
if (dp[i][n] >= k) {
chk = i; break;
}
}
string out;
per1(i, chk) {
int d;
rep(j, 10) {
if (n-j>=0&&k > dp[i-1][n - j]) {
k -= dp[i - 1][n - j];
}
else {
d = j; break;
}
}
out += '0' + d;
n -= d;
}
cout << out << endl;
return 0;
}