import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		String blank = " ";
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		for (int i = 1; i <= n; i++) {
			int x = i;
			if (x %3 == 0) {
				System.out.print(blank + i);
				continue;
			}
			if (x %10 == 3) {
				System.out.print(blank + i);
				continue;
			}
			while ((x/= 10) != 0) {
				if (x %10 == 3) {
					System.out.print(blank + i);
					break;
				}
			}
		}
		System.out.println("");
	}
} import java.io.IOException; IOException java.io import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) throws IOException {

		String blank = " ";
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		for (int i = 1; i <= n; i++) {
			int x = i;
			if (x %3 == 0) {
				System.out.print(blank + i);
				continue;
			}
			if (x %10 == 3) {
				System.out.print(blank + i);
				continue;
			}
			while ((x/= 10) != 0) {
				if (x %10 == 3) {
					System.out.print(blank + i);
					break;
				}
			}
		}
		System.out.println("");
	}
} Main public static void main(String[] args) throws IOException {

		String blank = " ";
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		for (int i = 1; i <= n; i++) {
			int x = i;
			if (x %3 == 0) {
				System.out.print(blank + i);
				continue;
			}
			if (x %10 == 3) {
				System.out.print(blank + i);
				continue;
			}
			while ((x/= 10) != 0) {
				if (x %10 == 3) {
					System.out.print(blank + i);
					break;
				}
			}
		}
		System.out.println("");
	} main {

		String blank = " ";
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		for (int i = 1; i <= n; i++) {
			int x = i;
			if (x %3 == 0) {
				System.out.print(blank + i);
				continue;
			}
			if (x %10 == 3) {
				System.out.print(blank + i);
				continue;
			}
			while ((x/= 10) != 0) {
				if (x %10 == 3) {
					System.out.print(blank + i);
					break;
				}
			}
		}
		System.out.println("");
	} String blank = " "; blank " " Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc for (int i = 1; i <= n; i++) {
			int x = i;
			if (x %3 == 0) {
				System.out.print(blank + i);
				continue;
			}
			if (x %10 == 3) {
				System.out.print(blank + i);
				continue;
			}
			while ((x/= 10) != 0) {
				if (x %10 == 3) {
					System.out.print(blank + i);
					break;
				}
			}
		} int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
			int x = i;
			if (x %3 == 0) {
				System.out.print(blank + i);
				continue;
			}
			if (x %10 == 3) {
				System.out.print(blank + i);
				continue;
			}
			while ((x/= 10) != 0) {
				if (x %10 == 3) {
					System.out.print(blank + i);
					break;
				}
			}
		} {
			int x = i;
			if (x %3 == 0) {
				System.out.print(blank + i);
				continue;
			}
			if (x %10 == 3) {
				System.out.print(blank + i);
				continue;
			}
			while ((x/= 10) != 0) {
				if (x %10 == 3) {
					System.out.print(blank + i);
					break;
				}
			}
		} int x = i; x i if (x %3 == 0) {
				System.out.print(blank + i);
				continue;
			} x %3 == 0 x %3 x 3 0 {
				System.out.print(blank + i);
				continue;
			} System.out.print(blank + i) System.out.print System.out System System.out blank + i blank i continue; if (x %10 == 3) {
				System.out.print(blank + i);
				continue;
			} x %10 == 3 x %10 x 10 3 {
				System.out.print(blank + i);
				continue;
			} System.out.print(blank + i) System.out.print System.out System System.out blank + i blank i continue; while ((x/= 10) != 0) {
				if (x %10 == 3) {
					System.out.print(blank + i);
					break;
				}
			} (x/= 10) != 0 (x/= 10) x 10 0 {
				if (x %10 == 3) {
					System.out.print(blank + i);
					break;
				}
			} if (x %10 == 3) {
					System.out.print(blank + i);
					break;
				} x %10 == 3 x %10 x 10 3 {
					System.out.print(blank + i);
					break;
				} System.out.print(blank + i) System.out.print System.out System System.out blank + i blank i break; System.out.println("") System.out.println System.out System System.out "" String[] args args public class Main {

	public static void main(String[] args) throws IOException {

		String blank = " ";
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		for (int i = 1; i <= n; i++) {
			int x = i;
			if (x %3 == 0) {
				System.out.print(blank + i);
				continue;
			}
			if (x %10 == 3) {
				System.out.print(blank + i);
				continue;
			}
			while ((x/= 10) != 0) {
				if (x %10 == 3) {
					System.out.print(blank + i);
					break;
				}
			}
		}
		System.out.println("");
	}
} public class Main {

	public static void main(String[] args) throws IOException {

		String blank = " ";
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		for (int i = 1; i <= n; i++) {
			int x = i;
			if (x %3 == 0) {
				System.out.print(blank + i);
				continue;
			}
			if (x %10 == 3) {
				System.out.print(blank + i);
				continue;
			}
			while ((x/= 10) != 0) {
				if (x %10 == 3) {
					System.out.print(blank + i);
					break;
				}
			}
		}
		System.out.println("");
	}
} Main
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		String blank = " ";
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		for (int i = 1; i <= n; i++) {
			int x = i;
			if (x %3 == 0) {
				System.out.print(blank + i);
				continue;
			}
			if (x %10 == 3) {
				System.out.print(blank + i);
				continue;
			}
			while ((x/= 10) != 0) {
				if (x %10 == 3) {
					System.out.print(blank + i);
					break;
				}
			}
		}
		System.out.println("");
	}
}