import java.util.Scanner;

public class Main {
	void call(int n) {
		for (int i = 1; i <= n; i++) {
			int x = i;
			if (x % 3 == 0) {
				System.out.printf(" %d", i);
				continue;
			}
			do {
				if (x % 10 == 3) {
					System.out.printf(" %d", i);
					break;
				}
				x /= 10;
			} while(x >= 1);
		}
		System.out.println();
	}
	public static void main(String[] args) {
		Main m = new Main();
		Scanner scan = new Scanner(System.in);
		m.call(scan.nextInt());
	}
} import java.util.Scanner; Scanner java.util public class Main {
	void call(int n) {
		for (int i = 1; i <= n; i++) {
			int x = i;
			if (x % 3 == 0) {
				System.out.printf(" %d", i);
				continue;
			}
			do {
				if (x % 10 == 3) {
					System.out.printf(" %d", i);
					break;
				}
				x /= 10;
			} while(x >= 1);
		}
		System.out.println();
	}
	public static void main(String[] args) {
		Main m = new Main();
		Scanner scan = new Scanner(System.in);
		m.call(scan.nextInt());
	}
} Main void call(int n) {
		for (int i = 1; i <= n; i++) {
			int x = i;
			if (x % 3 == 0) {
				System.out.printf(" %d", i);
				continue;
			}
			do {
				if (x % 10 == 3) {
					System.out.printf(" %d", i);
					break;
				}
				x /= 10;
			} while(x >= 1);
		}
		System.out.println();
	} call {
		for (int i = 1; i <= n; i++) {
			int x = i;
			if (x % 3 == 0) {
				System.out.printf(" %d", i);
				continue;
			}
			do {
				if (x % 10 == 3) {
					System.out.printf(" %d", i);
					break;
				}
				x /= 10;
			} while(x >= 1);
		}
		System.out.println();
	} for (int i = 1; i <= n; i++) {
			int x = i;
			if (x % 3 == 0) {
				System.out.printf(" %d", i);
				continue;
			}
			do {
				if (x % 10 == 3) {
					System.out.printf(" %d", i);
					break;
				}
				x /= 10;
			} while(x >= 1);
		} int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
			int x = i;
			if (x % 3 == 0) {
				System.out.printf(" %d", i);
				continue;
			}
			do {
				if (x % 10 == 3) {
					System.out.printf(" %d", i);
					break;
				}
				x /= 10;
			} while(x >= 1);
		} {
			int x = i;
			if (x % 3 == 0) {
				System.out.printf(" %d", i);
				continue;
			}
			do {
				if (x % 10 == 3) {
					System.out.printf(" %d", i);
					break;
				}
				x /= 10;
			} while(x >= 1);
		} int x = i; x i if (x % 3 == 0) {
				System.out.printf(" %d", i);
				continue;
			} x % 3 == 0 x % 3 x 3 0 {
				System.out.printf(" %d", i);
				continue;
			} System.out.printf(" %d", i) System.out.printf System.out System System.out " %d" i continue; do {
				if (x % 10 == 3) {
					System.out.printf(" %d", i);
					break;
				}
				x /= 10;
			} while(x >= 1); x >= 1 x 1 {
				if (x % 10 == 3) {
					System.out.printf(" %d", i);
					break;
				}
				x /= 10;
			} if (x % 10 == 3) {
					System.out.printf(" %d", i);
					break;
				} x % 10 == 3 x % 10 x 10 3 {
					System.out.printf(" %d", i);
					break;
				} System.out.printf(" %d", i) System.out.printf System.out System System.out " %d" i break; x /= 10 x 10 System.out.println() System.out.println System.out System System.out int n n public static void main(String[] args) {
		Main m = new Main();
		Scanner scan = new Scanner(System.in);
		m.call(scan.nextInt());
	} main {
		Main m = new Main();
		Scanner scan = new Scanner(System.in);
		m.call(scan.nextInt());
	} Main m = new Main(); m new Main() Scanner scan = new Scanner(System.in); scan new Scanner(System.in) m.call(scan.nextInt()) m.call m scan.nextInt() scan.nextInt scan String[] args args public class Main {
	void call(int n) {
		for (int i = 1; i <= n; i++) {
			int x = i;
			if (x % 3 == 0) {
				System.out.printf(" %d", i);
				continue;
			}
			do {
				if (x % 10 == 3) {
					System.out.printf(" %d", i);
					break;
				}
				x /= 10;
			} while(x >= 1);
		}
		System.out.println();
	}
	public static void main(String[] args) {
		Main m = new Main();
		Scanner scan = new Scanner(System.in);
		m.call(scan.nextInt());
	}
} public class Main {
	void call(int n) {
		for (int i = 1; i <= n; i++) {
			int x = i;
			if (x % 3 == 0) {
				System.out.printf(" %d", i);
				continue;
			}
			do {
				if (x % 10 == 3) {
					System.out.printf(" %d", i);
					break;
				}
				x /= 10;
			} while(x >= 1);
		}
		System.out.println();
	}
	public static void main(String[] args) {
		Main m = new Main();
		Scanner scan = new Scanner(System.in);
		m.call(scan.nextInt());
	}
} Main
import java.util.Scanner;

public class Main {
	void call(int n) {
		for (int i = 1; i <= n; i++) {
			int x = i;
			if (x % 3 == 0) {
				System.out.printf(" %d", i);
				continue;
			}
			do {
				if (x % 10 == 3) {
					System.out.printf(" %d", i);
					break;
				}
				x /= 10;
			} while(x >= 1);
		}
		System.out.println();
	}
	public static void main(String[] args) {
		Main m = new Main();
		Scanner scan = new Scanner(System.in);
		m.call(scan.nextInt());
	}
}