import java.util.*;
class Main{
	public static void main(String args[]){
		int n = 3;
		int i;
		Scanner scan = new Scanner(System.in);
		StringBuffer sb = new StringBuffer();
		i = scan.nextInt();
		while(true){
			if(i < n){
		        break;
			}
			if(n % 3 == 0 || Integer.toString(n).contains("3")){
				System.out.printf(" " + n);
			}
			n++;
		}
		System.out.println(sb);
	}
} import java.util.*; util.* java class Main{
	public static void main(String args[]){
		int n = 3;
		int i;
		Scanner scan = new Scanner(System.in);
		StringBuffer sb = new StringBuffer();
		i = scan.nextInt();
		while(true){
			if(i < n){
		        break;
			}
			if(n % 3 == 0 || Integer.toString(n).contains("3")){
				System.out.printf(" " + n);
			}
			n++;
		}
		System.out.println(sb);
	}
} Main public static void main(String args[]){
		int n = 3;
		int i;
		Scanner scan = new Scanner(System.in);
		StringBuffer sb = new StringBuffer();
		i = scan.nextInt();
		while(true){
			if(i < n){
		        break;
			}
			if(n % 3 == 0 || Integer.toString(n).contains("3")){
				System.out.printf(" " + n);
			}
			n++;
		}
		System.out.println(sb);
	} main {
		int n = 3;
		int i;
		Scanner scan = new Scanner(System.in);
		StringBuffer sb = new StringBuffer();
		i = scan.nextInt();
		while(true){
			if(i < n){
		        break;
			}
			if(n % 3 == 0 || Integer.toString(n).contains("3")){
				System.out.printf(" " + n);
			}
			n++;
		}
		System.out.println(sb);
	} int n = 3; n 3 int i; i Scanner scan = new Scanner(System.in); scan new Scanner(System.in) StringBuffer sb = new StringBuffer(); sb new StringBuffer() i = scan.nextInt() i scan.nextInt() scan.nextInt scan while(true){
			if(i < n){
		        break;
			}
			if(n % 3 == 0 || Integer.toString(n).contains("3")){
				System.out.printf(" " + n);
			}
			n++;
		} true {
			if(i < n){
		        break;
			}
			if(n % 3 == 0 || Integer.toString(n).contains("3")){
				System.out.printf(" " + n);
			}
			n++;
		} if(i < n){
		        break;
			} i < n i n {
		        break;
			} break; if(n % 3 == 0 || Integer.toString(n).contains("3")){
				System.out.printf(" " + n);
			} n % 3 == 0 || Integer.toString(n).contains("3") n % 3 == 0 n % 3 n 3 0 Integer.toString(n).contains("3") Integer.toString(n).contains Integer.toString(n) Integer.toString Integer n "3" {
				System.out.printf(" " + n);
			} System.out.printf(" " + n) System.out.printf System.out System System.out " " + n " " n n++ n System.out.println(sb) System.out.println System.out System System.out sb String args[] args
import java.util.*;
class Main{
	public static void main(String args[]){
		int n = 3;
		int i;
		Scanner scan = new Scanner(System.in);
		StringBuffer sb = new StringBuffer();
		i = scan.nextInt();
		while(true){
			if(i < n){
		        break;
			}
			if(n % 3 == 0 || Integer.toString(n).contains("3")){
				System.out.printf(" " + n);
			}
			n++;
		}
		System.out.println(sb);
	}
}