import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static String call(int n) {
		StringBuilder answer = new StringBuilder();
		for (int i = 3; i <= n; i++) {
			if (i % 3 == 0) {
				answer.append(" ").append(String.valueOf(i));
			} else {
				int tmp = i;
				while (tmp != 0) {
					if (tmp % 10 == 3) {
						answer.append(" ").append(String.valueOf(i));
						break;
					}
					tmp /= 10;
				}
			}
		}
		return answer.toString();
	}
	
	public static void main(String[] args) throws NumberFormatException, IOException {
		int n = Integer.parseInt((new BufferedReader(new InputStreamReader(System.in))).readLine());
		System.out.println(call(n));
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
	public static String call(int n) {
		StringBuilder answer = new StringBuilder();
		for (int i = 3; i <= n; i++) {
			if (i % 3 == 0) {
				answer.append(" ").append(String.valueOf(i));
			} else {
				int tmp = i;
				while (tmp != 0) {
					if (tmp % 10 == 3) {
						answer.append(" ").append(String.valueOf(i));
						break;
					}
					tmp /= 10;
				}
			}
		}
		return answer.toString();
	}
	
	public static void main(String[] args) throws NumberFormatException, IOException {
		int n = Integer.parseInt((new BufferedReader(new InputStreamReader(System.in))).readLine());
		System.out.println(call(n));
	}
} Main public static String call(int n) {
		StringBuilder answer = new StringBuilder();
		for (int i = 3; i <= n; i++) {
			if (i % 3 == 0) {
				answer.append(" ").append(String.valueOf(i));
			} else {
				int tmp = i;
				while (tmp != 0) {
					if (tmp % 10 == 3) {
						answer.append(" ").append(String.valueOf(i));
						break;
					}
					tmp /= 10;
				}
			}
		}
		return answer.toString();
	} call {
		StringBuilder answer = new StringBuilder();
		for (int i = 3; i <= n; i++) {
			if (i % 3 == 0) {
				answer.append(" ").append(String.valueOf(i));
			} else {
				int tmp = i;
				while (tmp != 0) {
					if (tmp % 10 == 3) {
						answer.append(" ").append(String.valueOf(i));
						break;
					}
					tmp /= 10;
				}
			}
		}
		return answer.toString();
	} StringBuilder answer = new StringBuilder(); answer new StringBuilder() for (int i = 3; i <= n; i++) {
			if (i % 3 == 0) {
				answer.append(" ").append(String.valueOf(i));
			} else {
				int tmp = i;
				while (tmp != 0) {
					if (tmp % 10 == 3) {
						answer.append(" ").append(String.valueOf(i));
						break;
					}
					tmp /= 10;
				}
			}
		} int i = 3; int i = 3; i 3 i <= n i n i++ i++ i {
			if (i % 3 == 0) {
				answer.append(" ").append(String.valueOf(i));
			} else {
				int tmp = i;
				while (tmp != 0) {
					if (tmp % 10 == 3) {
						answer.append(" ").append(String.valueOf(i));
						break;
					}
					tmp /= 10;
				}
			}
		} {
			if (i % 3 == 0) {
				answer.append(" ").append(String.valueOf(i));
			} else {
				int tmp = i;
				while (tmp != 0) {
					if (tmp % 10 == 3) {
						answer.append(" ").append(String.valueOf(i));
						break;
					}
					tmp /= 10;
				}
			}
		} if (i % 3 == 0) {
				answer.append(" ").append(String.valueOf(i));
			} else {
				int tmp = i;
				while (tmp != 0) {
					if (tmp % 10 == 3) {
						answer.append(" ").append(String.valueOf(i));
						break;
					}
					tmp /= 10;
				}
			} i % 3 == 0 i % 3 i 3 0 {
				answer.append(" ").append(String.valueOf(i));
			} answer.append(" ").append(String.valueOf(i)) answer.append(" ").append answer.append(" ") answer.append answer " " String.valueOf(i) String.valueOf String i {
				int tmp = i;
				while (tmp != 0) {
					if (tmp % 10 == 3) {
						answer.append(" ").append(String.valueOf(i));
						break;
					}
					tmp /= 10;
				}
			} int tmp = i; tmp i while (tmp != 0) {
					if (tmp % 10 == 3) {
						answer.append(" ").append(String.valueOf(i));
						break;
					}
					tmp /= 10;
				} tmp != 0 tmp 0 {
					if (tmp % 10 == 3) {
						answer.append(" ").append(String.valueOf(i));
						break;
					}
					tmp /= 10;
				} if (tmp % 10 == 3) {
						answer.append(" ").append(String.valueOf(i));
						break;
					} tmp % 10 == 3 tmp % 10 tmp 10 3 {
						answer.append(" ").append(String.valueOf(i));
						break;
					} answer.append(" ").append(String.valueOf(i)) answer.append(" ").append answer.append(" ") answer.append answer " " String.valueOf(i) String.valueOf String i break; tmp /= 10 tmp 10 return answer.toString(); answer.toString() answer.toString answer int n n public static void main(String[] args) throws NumberFormatException, IOException {
		int n = Integer.parseInt((new BufferedReader(new InputStreamReader(System.in))).readLine());
		System.out.println(call(n));
	} main {
		int n = Integer.parseInt((new BufferedReader(new InputStreamReader(System.in))).readLine());
		System.out.println(call(n));
	} int n = Integer.parseInt((new BufferedReader(new InputStreamReader(System.in))).readLine()); n Integer.parseInt((new BufferedReader(new InputStreamReader(System.in))).readLine()) Integer.parseInt Integer (new BufferedReader(new InputStreamReader(System.in))).readLine() (new BufferedReader(new InputStreamReader(System.in))).readLine (new BufferedReader(new InputStreamReader(System.in))) System.out.println(call(n)) System.out.println System.out System System.out call(n) call n String[] args args public class Main {
	public static String call(int n) {
		StringBuilder answer = new StringBuilder();
		for (int i = 3; i <= n; i++) {
			if (i % 3 == 0) {
				answer.append(" ").append(String.valueOf(i));
			} else {
				int tmp = i;
				while (tmp != 0) {
					if (tmp % 10 == 3) {
						answer.append(" ").append(String.valueOf(i));
						break;
					}
					tmp /= 10;
				}
			}
		}
		return answer.toString();
	}
	
	public static void main(String[] args) throws NumberFormatException, IOException {
		int n = Integer.parseInt((new BufferedReader(new InputStreamReader(System.in))).readLine());
		System.out.println(call(n));
	}
} public class Main {
	public static String call(int n) {
		StringBuilder answer = new StringBuilder();
		for (int i = 3; i <= n; i++) {
			if (i % 3 == 0) {
				answer.append(" ").append(String.valueOf(i));
			} else {
				int tmp = i;
				while (tmp != 0) {
					if (tmp % 10 == 3) {
						answer.append(" ").append(String.valueOf(i));
						break;
					}
					tmp /= 10;
				}
			}
		}
		return answer.toString();
	}
	
	public static void main(String[] args) throws NumberFormatException, IOException {
		int n = Integer.parseInt((new BufferedReader(new InputStreamReader(System.in))).readLine());
		System.out.println(call(n));
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static String call(int n) {
		StringBuilder answer = new StringBuilder();
		for (int i = 3; i <= n; i++) {
			if (i % 3 == 0) {
				answer.append(" ").append(String.valueOf(i));
			} else {
				int tmp = i;
				while (tmp != 0) {
					if (tmp % 10 == 3) {
						answer.append(" ").append(String.valueOf(i));
						break;
					}
					tmp /= 10;
				}
			}
		}
		return answer.toString();
	}
	
	public static void main(String[] args) throws NumberFormatException, IOException {
		int n = Integer.parseInt((new BufferedReader(new InputStreamReader(System.in))).readLine());
		System.out.println(call(n));
	}
}