const fs = require('fs');
const input = +fs.readFileSync('dev/stdin').toString();
let count = 0;
let num = 665;
while (count < input) {
num++;
if (String(num).includes('666')) count++;
}
console.log(num);
const fs = require('fs');
const input = +fs.readFileSync('dev/stdin').toString();
let count = 0;
let num = 665;
while (count < input) {
num++;
if (String(num).includes('666')) count++;
}
console.log(num);