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

public class Main {
	public static void main(String[] args) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(
					System.in));
			StringBuilder s=new StringBuilder(); 
			int val = Integer.parseInt(br.readLine());
			int x = 0;

			for (int i = 1; i <= val; i++) {
				if (i % 3 == 0 || i % 10 == 3) {
					s.append(" " + i);
				} else {
					x = i / 10;
					while (x != 0) {
						if (x % 10 == 3) {
							s.append(" " + i);
							break;
						}
						x /= 10;
					}
				}
			}
			System.out.println(s);
			br.close();
		} catch (Exception e) {
			System.err.println(e);
		}
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
	public static void main(String[] args) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(
					System.in));
			StringBuilder s=new StringBuilder(); 
			int val = Integer.parseInt(br.readLine());
			int x = 0;

			for (int i = 1; i <= val; i++) {
				if (i % 3 == 0 || i % 10 == 3) {
					s.append(" " + i);
				} else {
					x = i / 10;
					while (x != 0) {
						if (x % 10 == 3) {
							s.append(" " + i);
							break;
						}
						x /= 10;
					}
				}
			}
			System.out.println(s);
			br.close();
		} catch (Exception e) {
			System.err.println(e);
		}
	}
} Main public static void main(String[] args) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(
					System.in));
			StringBuilder s=new StringBuilder(); 
			int val = Integer.parseInt(br.readLine());
			int x = 0;

			for (int i = 1; i <= val; i++) {
				if (i % 3 == 0 || i % 10 == 3) {
					s.append(" " + i);
				} else {
					x = i / 10;
					while (x != 0) {
						if (x % 10 == 3) {
							s.append(" " + i);
							break;
						}
						x /= 10;
					}
				}
			}
			System.out.println(s);
			br.close();
		} catch (Exception e) {
			System.err.println(e);
		}
	} main {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(
					System.in));
			StringBuilder s=new StringBuilder(); 
			int val = Integer.parseInt(br.readLine());
			int x = 0;

			for (int i = 1; i <= val; i++) {
				if (i % 3 == 0 || i % 10 == 3) {
					s.append(" " + i);
				} else {
					x = i / 10;
					while (x != 0) {
						if (x % 10 == 3) {
							s.append(" " + i);
							break;
						}
						x /= 10;
					}
				}
			}
			System.out.println(s);
			br.close();
		} catch (Exception e) {
			System.err.println(e);
		}
	} try {
			BufferedReader br = new BufferedReader(new InputStreamReader(
					System.in));
			StringBuilder s=new StringBuilder(); 
			int val = Integer.parseInt(br.readLine());
			int x = 0;

			for (int i = 1; i <= val; i++) {
				if (i % 3 == 0 || i % 10 == 3) {
					s.append(" " + i);
				} else {
					x = i / 10;
					while (x != 0) {
						if (x % 10 == 3) {
							s.append(" " + i);
							break;
						}
						x /= 10;
					}
				}
			}
			System.out.println(s);
			br.close();
		} catch (Exception e) {
			System.err.println(e);
		} catch (Exception e) {
			System.err.println(e);
		} Exception e {
			System.err.println(e);
		} System.err.println(e) System.err.println System.err System System.err e {
			BufferedReader br = new BufferedReader(new InputStreamReader(
					System.in));
			StringBuilder s=new StringBuilder(); 
			int val = Integer.parseInt(br.readLine());
			int x = 0;

			for (int i = 1; i <= val; i++) {
				if (i % 3 == 0 || i % 10 == 3) {
					s.append(" " + i);
				} else {
					x = i / 10;
					while (x != 0) {
						if (x % 10 == 3) {
							s.append(" " + i);
							break;
						}
						x /= 10;
					}
				}
			}
			System.out.println(s);
			br.close();
		} BufferedReader br = new BufferedReader(new InputStreamReader(
					System.in)); br new BufferedReader(new InputStreamReader(
					System.in)) StringBuilder s=new StringBuilder(); s new StringBuilder() int val = Integer.parseInt(br.readLine()); val Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int x = 0; x 0 for (int i = 1; i <= val; i++) {
				if (i % 3 == 0 || i % 10 == 3) {
					s.append(" " + i);
				} else {
					x = i / 10;
					while (x != 0) {
						if (x % 10 == 3) {
							s.append(" " + i);
							break;
						}
						x /= 10;
					}
				}
			} int i = 1; int i = 1; i 1 i <= val i val i++ i++ i {
				if (i % 3 == 0 || i % 10 == 3) {
					s.append(" " + i);
				} else {
					x = i / 10;
					while (x != 0) {
						if (x % 10 == 3) {
							s.append(" " + i);
							break;
						}
						x /= 10;
					}
				}
			} {
				if (i % 3 == 0 || i % 10 == 3) {
					s.append(" " + i);
				} else {
					x = i / 10;
					while (x != 0) {
						if (x % 10 == 3) {
							s.append(" " + i);
							break;
						}
						x /= 10;
					}
				}
			} if (i % 3 == 0 || i % 10 == 3) {
					s.append(" " + i);
				} else {
					x = i / 10;
					while (x != 0) {
						if (x % 10 == 3) {
							s.append(" " + i);
							break;
						}
						x /= 10;
					}
				} i % 3 == 0 || i % 10 == 3 i % 3 == 0 i % 3 i 3 0 i % 10 == 3 i % 10 i 10 3 {
					s.append(" " + i);
				} s.append(" " + i) s.append s " " + i " " i {
					x = i / 10;
					while (x != 0) {
						if (x % 10 == 3) {
							s.append(" " + i);
							break;
						}
						x /= 10;
					}
				} x = i / 10 x i / 10 i 10 while (x != 0) {
						if (x % 10 == 3) {
							s.append(" " + i);
							break;
						}
						x /= 10;
					} x != 0 x 0 {
						if (x % 10 == 3) {
							s.append(" " + i);
							break;
						}
						x /= 10;
					} if (x % 10 == 3) {
							s.append(" " + i);
							break;
						} x % 10 == 3 x % 10 x 10 3 {
							s.append(" " + i);
							break;
						} s.append(" " + i) s.append s " " + i " " i break; x /= 10 x 10 System.out.println(s) System.out.println System.out System System.out s br.close() br.close br String[] args args public class Main {
	public static void main(String[] args) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(
					System.in));
			StringBuilder s=new StringBuilder(); 
			int val = Integer.parseInt(br.readLine());
			int x = 0;

			for (int i = 1; i <= val; i++) {
				if (i % 3 == 0 || i % 10 == 3) {
					s.append(" " + i);
				} else {
					x = i / 10;
					while (x != 0) {
						if (x % 10 == 3) {
							s.append(" " + i);
							break;
						}
						x /= 10;
					}
				}
			}
			System.out.println(s);
			br.close();
		} catch (Exception e) {
			System.err.println(e);
		}
	}
} public class Main {
	public static void main(String[] args) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(
					System.in));
			StringBuilder s=new StringBuilder(); 
			int val = Integer.parseInt(br.readLine());
			int x = 0;

			for (int i = 1; i <= val; i++) {
				if (i % 3 == 0 || i % 10 == 3) {
					s.append(" " + i);
				} else {
					x = i / 10;
					while (x != 0) {
						if (x % 10 == 3) {
							s.append(" " + i);
							break;
						}
						x /= 10;
					}
				}
			}
			System.out.println(s);
			br.close();
		} catch (Exception e) {
			System.err.println(e);
		}
	}
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(
					System.in));
			StringBuilder s=new StringBuilder(); 
			int val = Integer.parseInt(br.readLine());
			int x = 0;

			for (int i = 1; i <= val; i++) {
				if (i % 3 == 0 || i % 10 == 3) {
					s.append(" " + i);
				} else {
					x = i / 10;
					while (x != 0) {
						if (x % 10 == 3) {
							s.append(" " + i);
							break;
						}
						x /= 10;
					}
				}
			}
			System.out.println(s);
			br.close();
		} catch (Exception e) {
			System.err.println(e);
		}
	}
}