string N_str;
bool found = false;
void fn(string current, set<int>& used, int rem_len, bool compromised) {
if (found) return;
if (rem_len == 0) {
if (current.length() == N_str.length() && (compromised || current > N_str)) {
cout << current << endl;
found = true;
}
return;
}
int pos = current.length();
int limit = compromised ? 9 : (N_str[pos] - '0');
for (int d = 1; d <= 9; ++d) {
if (used.count(d)) continue; // digit already used
if (d > rem_len) continue; // not enough space left to fit d copies
// Check if using this digit fits in rem_len
if (!compromised && d < limit) continue; // would be smaller prefix
string next = current + string(d, '0' + d);
used.insert(d);
fn(next, used, rem_len - d, compromised || (d > limit));
used.erase(d);
}
}
void solve(int N) {
N_str = to_string(N + 1);
int len = N_str.length();
while (true) {
found = false;
set<int> used;
fn("", used, len, false);
if (found) break;
len++;
N_str = string(len - to_string(N + 1).length(), '0') + to_string(N + 1);
}
}
int32_t main()
{
fast;
int testcases=1;
// cin >> testcases;
while(testcases--)
{
int n;
cin >> n;
solve(n);
}
}