#include <iostream>
#include <string>
#include <cmath>
using namespace std;
bool is_valid(long long num, int* indices) {
char checklist[] = { '2', '0', '2', '1' };
int index = 0;
string ns = to_string(num);
for (int ci = 0; ci < ns.length(); ci++) {
if (index == 4) return true;
if (ns[ci] == checklist[index]) {
indices[index] = ci;
index++;
}
}
if (index == 4) return true;
else return false;
}
int main() {
long long n; // the n:th to be found
cin >> n;
long long cn = 0; // current nth
long long output = 0; // the - output..
for (long long i = 2021; i < pow(10, 12); i++) {
if (is_valid(i, indices)) {
cn++;
//cout <<cn << " : " << i << endl;
}
if (cn == n && is_valid(i, indices)) {
output = i;
break;
}
}
cout << output;
return 0;
}