import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { public static void main(String[] args) { BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); try { String[] box = read.readLine().split(" "); long[] num = new long[2]; for (int i = 0; i < 2; ++i) { num[i] = Long.parseLong(box[i]); } while (num[0] <= num[1]) { String ch = num[0] + ""; if (num[0] % 3 == 0) { System.out.println(num[0]); } else { for (int i = 0; i < ch.length(); ++i) { if (ch.charAt(i) == '3') { System.out.println(num[0]); break; } } } ++num[0]; } } catch (Exception e) { e.printStackTrace(); } } }