import java.util.*;

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

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