import java.util.Scanner;

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

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