import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner kb = new Scanner(System.in); int n = kb.nextInt(); int count = 1; int find = 666; while(true) { if(count == n) { System.out.println(find); break; } find++; if(String.valueOf(find).contains("666")) { count++; } } } }