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