#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>PII;
const int N = 2e5 + 10;
const int MOD = 998244353;
const int INF = 0X3F3F3F3F;
const int dx[] = {-1, 1, 0, 0, -1, -1, +1, +1};
const int dy[] = {0, 0, -1, 1, -1, +1, -1, +1};
const int M = 1e6 + 10;
int n;
int a[M];
bool check(int x)
{
string s = to_string(x);
reverse(s.begin(), s.end());
while(s.size() < 5) s += '0';
reverse(s.begin(), s.end());
for(int i = 0; i < 4; i ++)
{
for(int j = i + 1; j < 5; j ++)
{
if(s[i] == s[j]) return false;
}
}
return true;
}
int main()
{
int o = 0;
//进行预处理
for(int i = 99999; i >= 0; i --)
{
if(check(i)) a[++ o] = i;
}
int k;
cin >> k;
string s = to_string(a[k]);
reverse(s.begin(), s.end());
while(s.size() < 5) s += '0';
reverse(s.begin(), s.end());
cout << s << endl;
}