import java.util.Scanner;
class Main {
	int x,n = 0,a,b,c,d,e;
	public void pr() {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		if(n >= 3 && n <= 10000) {
			for(x = 3; x <= n;x++) {
				a = x % 3;
				b = x % 10;
				c = x / 10;
				d = x / 100;
				e = x / 1000;
				if(a == 0 || b == 3 || c == 3 || c % 10 == 3 || d == 3 || d % 10 == 3 || e == 3 || e % 10 == 3) {
					System.out.print(" " + x);
				}
			}
		}
		System.out.println();
	}
	public static void main(String[] args) {
		new Main().pr();
	}
} import java.util.Scanner; Scanner java.util class Main {
	int x,n = 0,a,b,c,d,e;
	public void pr() {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		if(n >= 3 && n <= 10000) {
			for(x = 3; x <= n;x++) {
				a = x % 3;
				b = x % 10;
				c = x / 10;
				d = x / 100;
				e = x / 1000;
				if(a == 0 || b == 3 || c == 3 || c % 10 == 3 || d == 3 || d % 10 == 3 || e == 3 || e % 10 == 3) {
					System.out.print(" " + x);
				}
			}
		}
		System.out.println();
	}
	public static void main(String[] args) {
		new Main().pr();
	}
} Main int x x n = 0 n 0 a a b b c c d d e; e public void pr() {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		if(n >= 3 && n <= 10000) {
			for(x = 3; x <= n;x++) {
				a = x % 3;
				b = x % 10;
				c = x / 10;
				d = x / 100;
				e = x / 1000;
				if(a == 0 || b == 3 || c == 3 || c % 10 == 3 || d == 3 || d % 10 == 3 || e == 3 || e % 10 == 3) {
					System.out.print(" " + x);
				}
			}
		}
		System.out.println();
	} pr {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		if(n >= 3 && n <= 10000) {
			for(x = 3; x <= n;x++) {
				a = x % 3;
				b = x % 10;
				c = x / 10;
				d = x / 100;
				e = x / 1000;
				if(a == 0 || b == 3 || c == 3 || c % 10 == 3 || d == 3 || d % 10 == 3 || e == 3 || e % 10 == 3) {
					System.out.print(" " + x);
				}
			}
		}
		System.out.println();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) n = sc.nextInt() n sc.nextInt() sc.nextInt sc if(n >= 3 && n <= 10000) {
			for(x = 3; x <= n;x++) {
				a = x % 3;
				b = x % 10;
				c = x / 10;
				d = x / 100;
				e = x / 1000;
				if(a == 0 || b == 3 || c == 3 || c % 10 == 3 || d == 3 || d % 10 == 3 || e == 3 || e % 10 == 3) {
					System.out.print(" " + x);
				}
			}
		} n >= 3 && n <= 10000 n >= 3 n 3 n <= 10000 n 10000 {
			for(x = 3; x <= n;x++) {
				a = x % 3;
				b = x % 10;
				c = x / 10;
				d = x / 100;
				e = x / 1000;
				if(a == 0 || b == 3 || c == 3 || c % 10 == 3 || d == 3 || d % 10 == 3 || e == 3 || e % 10 == 3) {
					System.out.print(" " + x);
				}
			}
		} for(x = 3; x <= n;x++) {
				a = x % 3;
				b = x % 10;
				c = x / 10;
				d = x / 100;
				e = x / 1000;
				if(a == 0 || b == 3 || c == 3 || c % 10 == 3 || d == 3 || d % 10 == 3 || e == 3 || e % 10 == 3) {
					System.out.print(" " + x);
				}
			} x = 3; x = 3 x 3 x <= n x n x++ x++ x {
				a = x % 3;
				b = x % 10;
				c = x / 10;
				d = x / 100;
				e = x / 1000;
				if(a == 0 || b == 3 || c == 3 || c % 10 == 3 || d == 3 || d % 10 == 3 || e == 3 || e % 10 == 3) {
					System.out.print(" " + x);
				}
			} {
				a = x % 3;
				b = x % 10;
				c = x / 10;
				d = x / 100;
				e = x / 1000;
				if(a == 0 || b == 3 || c == 3 || c % 10 == 3 || d == 3 || d % 10 == 3 || e == 3 || e % 10 == 3) {
					System.out.print(" " + x);
				}
			} a = x % 3 a x % 3 x 3 b = x % 10 b x % 10 x 10 c = x / 10 c x / 10 x 10 d = x / 100 d x / 100 x 100 e = x / 1000 e x / 1000 x 1000 if(a == 0 || b == 3 || c == 3 || c % 10 == 3 || d == 3 || d % 10 == 3 || e == 3 || e % 10 == 3) {
					System.out.print(" " + x);
				} a == 0 || b == 3 || c == 3 || c % 10 == 3 || d == 3 || d % 10 == 3 || e == 3 || e % 10 == 3 e == 3 d % 10 == 3 d == 3 c % 10 == 3 c == 3 a == 0 || b == 3 || c == 3 || c % 10 == 3 || d == 3 || d % 10 == 3 || e == 3 || e % 10 == 3 a == 0 a 0 b == 3 b 3 c == 3 c 3 c % 10 == 3 c % 10 c 10 3 d == 3 d 3 d % 10 == 3 d % 10 d 10 3 e == 3 e 3 e % 10 == 3 e % 10 e 10 3 {
					System.out.print(" " + x);
				} System.out.print(" " + x) System.out.print System.out System System.out " " + x " " x System.out.println() System.out.println System.out System System.out public static void main(String[] args) {
		new Main().pr();
	} main {
		new Main().pr();
	} new Main().pr() new Main().pr new Main() String[] args args
import java.util.Scanner;
class Main {
	int x,n = 0,a,b,c,d,e;
	public void pr() {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		if(n >= 3 && n <= 10000) {
			for(x = 3; x <= n;x++) {
				a = x % 3;
				b = x % 10;
				c = x / 10;
				d = x / 100;
				e = x / 1000;
				if(a == 0 || b == 3 || c == 3 || c % 10 == 3 || d == 3 || d % 10 == 3 || e == 3 || e % 10 == 3) {
					System.out.print(" " + x);
				}
			}
		}
		System.out.println();
	}
	public static void main(String[] args) {
		new Main().pr();
	}
}