#include <iostream>
#include <set>
#include <string>
using namespace std;
int main() {
int k;
cin >> k;
int count = 0;
string res = "";
for (int i = 99999; i >= 0; i --) {
string num_str = to_string(i);
if (num_str.size() < 5) {
num_str.insert(num_str.begin(), 5 - num_str.size(), '0');
}
// 根据set大小是否 等于5 来判断是否为好数
set<char> st;
for (char ch : num_str) {
st.insert(ch);
}
if (st.size() == 5) {
count ++;
} else {
continue;
}
if (k == count) {
res = num_str;
break;
}
}
cout << res << endl;
return 0;
}
// 64 位输出请用 printf("%lld")