import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner kb = new Scanner( System.in);	

		int n = kb.nextInt();
		int i = 1;
		do {
			int x=i;
			
			if( 0 == x%3 ) {
				System.out.print( " "+i );
			} else {
				do {
					if( 3 == x%10 ) {
						System.out.print( " "+i );
						break;
					}
					x /= 10;
				} while( 0!=x );
			}
			
		} while ( ++i <= n );
		
		System.out.print( "\n" );
	}
} import java.util.Scanner; Scanner java.util class Main {
	public static void main(String[] args) {
		Scanner kb = new Scanner( System.in);	

		int n = kb.nextInt();
		int i = 1;
		do {
			int x=i;
			
			if( 0 == x%3 ) {
				System.out.print( " "+i );
			} else {
				do {
					if( 3 == x%10 ) {
						System.out.print( " "+i );
						break;
					}
					x /= 10;
				} while( 0!=x );
			}
			
		} while ( ++i <= n );
		
		System.out.print( "\n" );
	}
} Main public static void main(String[] args) {
		Scanner kb = new Scanner( System.in);	

		int n = kb.nextInt();
		int i = 1;
		do {
			int x=i;
			
			if( 0 == x%3 ) {
				System.out.print( " "+i );
			} else {
				do {
					if( 3 == x%10 ) {
						System.out.print( " "+i );
						break;
					}
					x /= 10;
				} while( 0!=x );
			}
			
		} while ( ++i <= n );
		
		System.out.print( "\n" );
	} main {
		Scanner kb = new Scanner( System.in);	

		int n = kb.nextInt();
		int i = 1;
		do {
			int x=i;
			
			if( 0 == x%3 ) {
				System.out.print( " "+i );
			} else {
				do {
					if( 3 == x%10 ) {
						System.out.print( " "+i );
						break;
					}
					x /= 10;
				} while( 0!=x );
			}
			
		} while ( ++i <= n );
		
		System.out.print( "\n" );
	} Scanner kb = new Scanner( System.in); kb new Scanner( System.in) int n = kb.nextInt(); n kb.nextInt() kb.nextInt kb int i = 1; i 1 do {
			int x=i;
			
			if( 0 == x%3 ) {
				System.out.print( " "+i );
			} else {
				do {
					if( 3 == x%10 ) {
						System.out.print( " "+i );
						break;
					}
					x /= 10;
				} while( 0!=x );
			}
			
		} while ( ++i <= n ); ++i <= n ++i i n {
			int x=i;
			
			if( 0 == x%3 ) {
				System.out.print( " "+i );
			} else {
				do {
					if( 3 == x%10 ) {
						System.out.print( " "+i );
						break;
					}
					x /= 10;
				} while( 0!=x );
			}
			
		} int x=i; x i if( 0 == x%3 ) {
				System.out.print( " "+i );
			} else {
				do {
					if( 3 == x%10 ) {
						System.out.print( " "+i );
						break;
					}
					x /= 10;
				} while( 0!=x );
			} 0 == x%3 0 x%3 x 3 {
				System.out.print( " "+i );
			} System.out.print( " "+i ) System.out.print System.out System System.out " "+i " " i {
				do {
					if( 3 == x%10 ) {
						System.out.print( " "+i );
						break;
					}
					x /= 10;
				} while( 0!=x );
			} do {
					if( 3 == x%10 ) {
						System.out.print( " "+i );
						break;
					}
					x /= 10;
				} while( 0!=x ); 0!=x 0 x {
					if( 3 == x%10 ) {
						System.out.print( " "+i );
						break;
					}
					x /= 10;
				} if( 3 == x%10 ) {
						System.out.print( " "+i );
						break;
					} 3 == x%10 3 x%10 x 10 {
						System.out.print( " "+i );
						break;
					} System.out.print( " "+i ) System.out.print System.out System System.out " "+i " " i break; x /= 10 x 10 System.out.print( "\n" ) System.out.print System.out System System.out "\n" String[] args args
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner kb = new Scanner( System.in);	

		int n = kb.nextInt();
		int i = 1;
		do {
			int x=i;
			
			if( 0 == x%3 ) {
				System.out.print( " "+i );
			} else {
				do {
					if( 3 == x%10 ) {
						System.out.print( " "+i );
						break;
					}
					x /= 10;
				} while( 0!=x );
			}
			
		} while ( ++i <= n );
		
		System.out.print( "\n" );
	}
}