import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

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

	public static void main(String[] args){
		int n = scan.nextInt();
		int i = 1;
		while(i <= n){
			int x = i;
			if(x % 3 == 0){
				System.out.printf(" %d", i);
			} else{
				while(x != 0){
					if(x % 10 == 3){
						System.out.printf(" %d", i);
						break;
					}
					x /= 10;
				}
			}
			i++;
		}
		System.out.println("");
	}
} Main private static final Scanner scan = new Scanner(System.in); scan new Scanner(System.in) public static void main(String[] args){
		int n = scan.nextInt();
		int i = 1;
		while(i <= n){
			int x = i;
			if(x % 3 == 0){
				System.out.printf(" %d", i);
			} else{
				while(x != 0){
					if(x % 10 == 3){
						System.out.printf(" %d", i);
						break;
					}
					x /= 10;
				}
			}
			i++;
		}
		System.out.println("");
	} main {
		int n = scan.nextInt();
		int i = 1;
		while(i <= n){
			int x = i;
			if(x % 3 == 0){
				System.out.printf(" %d", i);
			} else{
				while(x != 0){
					if(x % 10 == 3){
						System.out.printf(" %d", i);
						break;
					}
					x /= 10;
				}
			}
			i++;
		}
		System.out.println("");
	} int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int i = 1; i 1 while(i <= n){
			int x = i;
			if(x % 3 == 0){
				System.out.printf(" %d", i);
			} else{
				while(x != 0){
					if(x % 10 == 3){
						System.out.printf(" %d", i);
						break;
					}
					x /= 10;
				}
			}
			i++;
		} i <= n i n {
			int x = i;
			if(x % 3 == 0){
				System.out.printf(" %d", i);
			} else{
				while(x != 0){
					if(x % 10 == 3){
						System.out.printf(" %d", i);
						break;
					}
					x /= 10;
				}
			}
			i++;
		} int x = i; x i if(x % 3 == 0){
				System.out.printf(" %d", i);
			} else{
				while(x != 0){
					if(x % 10 == 3){
						System.out.printf(" %d", i);
						break;
					}
					x /= 10;
				}
			} x % 3 == 0 x % 3 x 3 0 {
				System.out.printf(" %d", i);
			} System.out.printf(" %d", i) System.out.printf System.out System System.out " %d" i {
				while(x != 0){
					if(x % 10 == 3){
						System.out.printf(" %d", i);
						break;
					}
					x /= 10;
				}
			} while(x != 0){
					if(x % 10 == 3){
						System.out.printf(" %d", i);
						break;
					}
					x /= 10;
				} x != 0 x 0 {
					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 i++ i System.out.println("") System.out.println System.out System System.out "" String[] args args public class Main{
	private static final Scanner scan = new Scanner(System.in);

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

	public static void main(String[] args){
		int n = scan.nextInt();
		int i = 1;
		while(i <= n){
			int x = i;
			if(x % 3 == 0){
				System.out.printf(" %d", i);
			} else{
				while(x != 0){
					if(x % 10 == 3){
						System.out.printf(" %d", i);
						break;
					}
					x /= 10;
				}
			}
			i++;
		}
		System.out.println("");
	}
} Main
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		int n = scan.nextInt();
		int i = 1;
		while(i <= n){
			int x = i;
			if(x % 3 == 0){
				System.out.printf(" %d", i);
			} else{
				while(x != 0){
					if(x % 10 == 3){
						System.out.printf(" %d", i);
						break;
					}
					x /= 10;
				}
			}
			i++;
		}
		System.out.println("");
	}
}