import java.io.*;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		
		int n = Integer.parseInt(br.readLine().toString());
		int i = 1;
		int x;
		
		do {
			x = i;
			
			if (x % 3 == 0) {
				sb.append(" ").append(i);
				if ((i + 1) <= n) continue;
			} else {
				do {
					if (x % 10 == 3 || String.valueOf(x).matches(".*[3].*")) sb.append(" ").append(i);
					if ((i + 1) <= n) break;
					
					x /= 10;
					
					if (x == 0) {
						continue;
					} else {
						break;
					}
				} while (true);
			}
		} while (++i <= n);
		
		System.out.println(sb);
	}
} import java.io.*; io.* java public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		
		int n = Integer.parseInt(br.readLine().toString());
		int i = 1;
		int x;
		
		do {
			x = i;
			
			if (x % 3 == 0) {
				sb.append(" ").append(i);
				if ((i + 1) <= n) continue;
			} else {
				do {
					if (x % 10 == 3 || String.valueOf(x).matches(".*[3].*")) sb.append(" ").append(i);
					if ((i + 1) <= n) break;
					
					x /= 10;
					
					if (x == 0) {
						continue;
					} else {
						break;
					}
				} while (true);
			}
		} while (++i <= n);
		
		System.out.println(sb);
	}
} Main public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		
		int n = Integer.parseInt(br.readLine().toString());
		int i = 1;
		int x;
		
		do {
			x = i;
			
			if (x % 3 == 0) {
				sb.append(" ").append(i);
				if ((i + 1) <= n) continue;
			} else {
				do {
					if (x % 10 == 3 || String.valueOf(x).matches(".*[3].*")) sb.append(" ").append(i);
					if ((i + 1) <= n) break;
					
					x /= 10;
					
					if (x == 0) {
						continue;
					} else {
						break;
					}
				} while (true);
			}
		} while (++i <= n);
		
		System.out.println(sb);
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		
		int n = Integer.parseInt(br.readLine().toString());
		int i = 1;
		int x;
		
		do {
			x = i;
			
			if (x % 3 == 0) {
				sb.append(" ").append(i);
				if ((i + 1) <= n) continue;
			} else {
				do {
					if (x % 10 == 3 || String.valueOf(x).matches(".*[3].*")) sb.append(" ").append(i);
					if ((i + 1) <= n) break;
					
					x /= 10;
					
					if (x == 0) {
						continue;
					} else {
						break;
					}
				} while (true);
			}
		} while (++i <= n);
		
		System.out.println(sb);
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) StringBuilder sb = new StringBuilder(); sb new StringBuilder() int n = Integer.parseInt(br.readLine().toString()); n Integer.parseInt(br.readLine().toString()) Integer.parseInt Integer br.readLine().toString() br.readLine().toString br.readLine() br.readLine br int i = 1; i 1 int x; x do {
			x = i;
			
			if (x % 3 == 0) {
				sb.append(" ").append(i);
				if ((i + 1) <= n) continue;
			} else {
				do {
					if (x % 10 == 3 || String.valueOf(x).matches(".*[3].*")) sb.append(" ").append(i);
					if ((i + 1) <= n) break;
					
					x /= 10;
					
					if (x == 0) {
						continue;
					} else {
						break;
					}
				} while (true);
			}
		} while (++i <= n); ++i <= n ++i i n {
			x = i;
			
			if (x % 3 == 0) {
				sb.append(" ").append(i);
				if ((i + 1) <= n) continue;
			} else {
				do {
					if (x % 10 == 3 || String.valueOf(x).matches(".*[3].*")) sb.append(" ").append(i);
					if ((i + 1) <= n) break;
					
					x /= 10;
					
					if (x == 0) {
						continue;
					} else {
						break;
					}
				} while (true);
			}
		} x = i x i if (x % 3 == 0) {
				sb.append(" ").append(i);
				if ((i + 1) <= n) continue;
			} else {
				do {
					if (x % 10 == 3 || String.valueOf(x).matches(".*[3].*")) sb.append(" ").append(i);
					if ((i + 1) <= n) break;
					
					x /= 10;
					
					if (x == 0) {
						continue;
					} else {
						break;
					}
				} while (true);
			} x % 3 == 0 x % 3 x 3 0 {
				sb.append(" ").append(i);
				if ((i + 1) <= n) continue;
			} sb.append(" ").append(i) sb.append(" ").append sb.append(" ") sb.append sb " " i if ((i + 1) <= n) continue; (i + 1) <= n (i + 1) i 1 n continue; {
				do {
					if (x % 10 == 3 || String.valueOf(x).matches(".*[3].*")) sb.append(" ").append(i);
					if ((i + 1) <= n) break;
					
					x /= 10;
					
					if (x == 0) {
						continue;
					} else {
						break;
					}
				} while (true);
			} do {
					if (x % 10 == 3 || String.valueOf(x).matches(".*[3].*")) sb.append(" ").append(i);
					if ((i + 1) <= n) break;
					
					x /= 10;
					
					if (x == 0) {
						continue;
					} else {
						break;
					}
				} while (true); true {
					if (x % 10 == 3 || String.valueOf(x).matches(".*[3].*")) sb.append(" ").append(i);
					if ((i + 1) <= n) break;
					
					x /= 10;
					
					if (x == 0) {
						continue;
					} else {
						break;
					}
				} if (x % 10 == 3 || String.valueOf(x).matches(".*[3].*")) sb.append(" ").append(i); x % 10 == 3 || String.valueOf(x).matches(".*[3].*") x % 10 == 3 x % 10 x 10 3 String.valueOf(x).matches(".*[3].*") String.valueOf(x).matches String.valueOf(x) String.valueOf String x ".*[3].*" sb.append(" ").append(i) sb.append(" ").append sb.append(" ") sb.append sb " " i if ((i + 1) <= n) break; (i + 1) <= n (i + 1) i 1 n break; x /= 10 x 10 if (x == 0) {
						continue;
					} else {
						break;
					} x == 0 x 0 {
						continue;
					} continue; {
						break;
					} break; System.out.println(sb) System.out.println System.out System System.out sb String[] args args public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		
		int n = Integer.parseInt(br.readLine().toString());
		int i = 1;
		int x;
		
		do {
			x = i;
			
			if (x % 3 == 0) {
				sb.append(" ").append(i);
				if ((i + 1) <= n) continue;
			} else {
				do {
					if (x % 10 == 3 || String.valueOf(x).matches(".*[3].*")) sb.append(" ").append(i);
					if ((i + 1) <= n) break;
					
					x /= 10;
					
					if (x == 0) {
						continue;
					} else {
						break;
					}
				} while (true);
			}
		} while (++i <= n);
		
		System.out.println(sb);
	}
} public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		
		int n = Integer.parseInt(br.readLine().toString());
		int i = 1;
		int x;
		
		do {
			x = i;
			
			if (x % 3 == 0) {
				sb.append(" ").append(i);
				if ((i + 1) <= n) continue;
			} else {
				do {
					if (x % 10 == 3 || String.valueOf(x).matches(".*[3].*")) sb.append(" ").append(i);
					if ((i + 1) <= n) break;
					
					x /= 10;
					
					if (x == 0) {
						continue;
					} else {
						break;
					}
				} while (true);
			}
		} while (++i <= n);
		
		System.out.println(sb);
	}
} Main
import java.io.*;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		
		int n = Integer.parseInt(br.readLine().toString());
		int i = 1;
		int x;
		
		do {
			x = i;
			
			if (x % 3 == 0) {
				sb.append(" ").append(i);
				if ((i + 1) <= n) continue;
			} else {
				do {
					if (x % 10 == 3 || String.valueOf(x).matches(".*[3].*")) sb.append(" ").append(i);
					if ((i + 1) <= n) break;
					
					x /= 10;
					
					if (x == 0) {
						continue;
					} else {
						break;
					}
				} while (true);
			}
		} while (++i <= n);
		
		System.out.println(sb);
	}
}