#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int n, m;
struct xx {
int a, b;
} s[N];
bool cmp(xx a, xx b) {
if (a.b != b.b) {
return a.b < b.b;
} else {
return a.a < b.a;
}
}
int x;
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
x = i;
s[i].a = i;
while (x) {
s[i].b += x % 10;
x /= 10;
}
}
sort(s + 1, s + n + 1, cmp);
cout<<s[m].a;
return 0;
}