import java.util.*;

public class Main {
	public static void main(String[] args) {
				
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int i = 3;
		while(i <= n) {
			if(i % 3 == 0 || String.valueOf(i).contains("3")) {
				Integer.valueOf(i);
				System.out.printf(" %d", i);
			}
			i++;
		}
		System.out.printf("\n");
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
				
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int i = 3;
		while(i <= n) {
			if(i % 3 == 0 || String.valueOf(i).contains("3")) {
				Integer.valueOf(i);
				System.out.printf(" %d", i);
			}
			i++;
		}
		System.out.printf("\n");
	}
} Main public static void main(String[] args) {
				
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int i = 3;
		while(i <= n) {
			if(i % 3 == 0 || String.valueOf(i).contains("3")) {
				Integer.valueOf(i);
				System.out.printf(" %d", i);
			}
			i++;
		}
		System.out.printf("\n");
	} main {
				
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int i = 3;
		while(i <= n) {
			if(i % 3 == 0 || String.valueOf(i).contains("3")) {
				Integer.valueOf(i);
				System.out.printf(" %d", i);
			}
			i++;
		}
		System.out.printf("\n");
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int i = 3; i 3 while(i <= n) {
			if(i % 3 == 0 || String.valueOf(i).contains("3")) {
				Integer.valueOf(i);
				System.out.printf(" %d", i);
			}
			i++;
		} i <= n i n {
			if(i % 3 == 0 || String.valueOf(i).contains("3")) {
				Integer.valueOf(i);
				System.out.printf(" %d", i);
			}
			i++;
		} if(i % 3 == 0 || String.valueOf(i).contains("3")) {
				Integer.valueOf(i);
				System.out.printf(" %d", i);
			} i % 3 == 0 || String.valueOf(i).contains("3") i % 3 == 0 i % 3 i 3 0 String.valueOf(i).contains("3") String.valueOf(i).contains String.valueOf(i) String.valueOf String i "3" {
				Integer.valueOf(i);
				System.out.printf(" %d", i);
			} Integer.valueOf(i) Integer.valueOf Integer i System.out.printf(" %d", i) System.out.printf System.out System System.out " %d" i i++ i System.out.printf("\n") System.out.printf System.out System System.out "\n" String[] args args public class Main {
	public static void main(String[] args) {
				
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int i = 3;
		while(i <= n) {
			if(i % 3 == 0 || String.valueOf(i).contains("3")) {
				Integer.valueOf(i);
				System.out.printf(" %d", i);
			}
			i++;
		}
		System.out.printf("\n");
	}
} public class Main {
	public static void main(String[] args) {
				
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int i = 3;
		while(i <= n) {
			if(i % 3 == 0 || String.valueOf(i).contains("3")) {
				Integer.valueOf(i);
				System.out.printf(" %d", i);
			}
			i++;
		}
		System.out.printf("\n");
	}
} Main
import java.util.*;

public class Main {
	public static void main(String[] args) {
				
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int i = 3;
		while(i <= n) {
			if(i % 3 == 0 || String.valueOf(i).contains("3")) {
				Integer.valueOf(i);
				System.out.printf(" %d", i);
			}
			i++;
		}
		System.out.printf("\n");
	}
}