#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
long long radix_global;
bool decreasing(long long n){
if (n < 10){
return true;
}
int last = n % 10;
n = n / 10;
int next_last = n % 10;
int radix = 1;
while (n != 0 ){
radix *= 10;
if (next_last <= last){
radix_global = radix;
return false;
}
last = next_last;
n = n / 10;
next_last = n% 10;
}
return true;
}
int main(){
cin.tie(NULL);
ios::sync_with_stdio(false);
long long n;
cin >> n;
long long index = 0;
long long number = -1;
if (n > 1022){
cout << -1;
return 0;
}
while (number != n){
// cout << index << '\n';
if (decreasing(index)) {
number++;
index++;
}else {
index /= radix_global;
index *= radix_global;
index += radix_global;
}
}
cout << index-1;
// cout << decreasing(10);
return 0;
}