import java.util.*; import java.util.regex.*; import java.util.Collections; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int a = in.nextInt(); int b = in.nextInt(); ArrayList list = new ArrayList(); String regex = "3"; Pattern p = Pattern.compile(regex); for (int i = a; i <= b ; i++) { //System.out.println(i); if (i % 3 == 0) { //System.out.println(i); list.add (i); } else { String str = String.valueOf(i); if (p.matcher(str).find()) { list.add(i); } } } Collections.sort(list); //System.out.println(list); for ( int i = 0 ; i < list.size() ; i++ ) { System.out.println(list.get(i)); } } }