import java.io.*;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(br.readLine());
		
		for (int i = 1; i <= n; i++) {
			// CHECK_NUM  3??§???????????????
			if (i%3 == 0) {
				System.out.print(" " + i);
				continue;
			}
			
			// INCLIDE 3  ??°??????3?????????
			for (int tmp = i; tmp > 0; tmp/=10) {
				if (tmp % 10 == 3) {
					System.out.print(" " + i);
					break;
				}
			}
		}
		
		System.out.println();
	}
} import java.io.*; io.* java class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(br.readLine());
		
		for (int i = 1; i <= n; i++) {
			// CHECK_NUM  3??§???????????????
			if (i%3 == 0) {
				System.out.print(" " + i);
				continue;
			}
			
			// INCLIDE 3  ??°??????3?????????
			for (int tmp = i; tmp > 0; tmp/=10) {
				if (tmp % 10 == 3) {
					System.out.print(" " + i);
					break;
				}
			}
		}
		
		System.out.println();
	}
} Main public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(br.readLine());
		
		for (int i = 1; i <= n; i++) {
			// CHECK_NUM  3??§???????????????
			if (i%3 == 0) {
				System.out.print(" " + i);
				continue;
			}
			
			// INCLIDE 3  ??°??????3?????????
			for (int tmp = i; tmp > 0; tmp/=10) {
				if (tmp % 10 == 3) {
					System.out.print(" " + i);
					break;
				}
			}
		}
		
		System.out.println();
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(br.readLine());
		
		for (int i = 1; i <= n; i++) {
			// CHECK_NUM  3??§???????????????
			if (i%3 == 0) {
				System.out.print(" " + i);
				continue;
			}
			
			// INCLIDE 3  ??°??????3?????????
			for (int tmp = i; tmp > 0; tmp/=10) {
				if (tmp % 10 == 3) {
					System.out.print(" " + i);
					break;
				}
			}
		}
		
		System.out.println();
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br for (int i = 1; i <= n; i++) {
			// CHECK_NUM  3??§???????????????
			if (i%3 == 0) {
				System.out.print(" " + i);
				continue;
			}
			
			// INCLIDE 3  ??°??????3?????????
			for (int tmp = i; tmp > 0; tmp/=10) {
				if (tmp % 10 == 3) {
					System.out.print(" " + i);
					break;
				}
			}
		} int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
			// CHECK_NUM  3??§???????????????
			if (i%3 == 0) {
				System.out.print(" " + i);
				continue;
			}
			
			// INCLIDE 3  ??°??????3?????????
			for (int tmp = i; tmp > 0; tmp/=10) {
				if (tmp % 10 == 3) {
					System.out.print(" " + i);
					break;
				}
			}
		} {
			// CHECK_NUM  3??§???????????????
			if (i%3 == 0) {
				System.out.print(" " + i);
				continue;
			}
			
			// INCLIDE 3  ??°??????3?????????
			for (int tmp = i; tmp > 0; tmp/=10) {
				if (tmp % 10 == 3) {
					System.out.print(" " + i);
					break;
				}
			}
		} if (i%3 == 0) {
				System.out.print(" " + i);
				continue;
			} i%3 == 0 i%3 i 3 0 {
				System.out.print(" " + i);
				continue;
			} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i continue; for (int tmp = i; tmp > 0; tmp/=10) {
				if (tmp % 10 == 3) {
					System.out.print(" " + i);
					break;
				}
			} int tmp = i; int tmp = i; tmp i tmp > 0 tmp 0 tmp/=10 tmp/=10 tmp 10 {
				if (tmp % 10 == 3) {
					System.out.print(" " + i);
					break;
				}
			} {
				if (tmp % 10 == 3) {
					System.out.print(" " + i);
					break;
				}
			} if (tmp % 10 == 3) {
					System.out.print(" " + i);
					break;
				} tmp % 10 == 3 tmp % 10 tmp 10 3 {
					System.out.print(" " + i);
					break;
				} System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i break; System.out.println() System.out.println System.out System System.out String args[] args
import java.io.*;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(br.readLine());
		
		for (int i = 1; i <= n; i++) {
			// CHECK_NUM  3??§???????????????
			if (i%3 == 0) {
				System.out.print(" " + i);
				continue;
			}
			
			// INCLIDE 3  ??°??????3?????????
			for (int tmp = i; tmp > 0; tmp/=10) {
				if (tmp % 10 == 3) {
					System.out.print(" " + i);
					break;
				}
			}
		}
		
		System.out.println();
	}
}