https://www.acmicpc.net/problem/1436
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define fastio ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define int int64_t
using namespace std;
int Sol(int n){
for(int i = 666; ; i++){
if(to_string(i).find("666") != -1) n--;
if(!n) return i;
}
}
int32_t main() {
fastio;
int n; cin >> n;
cout << Sol(n) << "\n";
}