import java.util.Scanner;

public class Main {

    static boolean check_num( int x ) {
    	if( ( x % 3 == 0 ) ) {
    		System.out.print( " " + x );
    		return true;
    	} else {
    		return false;
    	}
    }

    static boolean include3( int x, int i ) {
    	if ( ( x % 10 == 3 ) ) {
    		System.out.print( " " + i );
    		return true;
    	} else {
    		return false;
    	}
    }

    public static void main(String[] args) {

        int num = 0;

        Scanner sc= new Scanner( System.in );

        num = sc.nextInt();
        for ( int i = 1 ; i <= num ; i++ ) {
        	if ( check_num( i ) ) {
        		continue;
        	} else {
        		int x = i;
        		while ( x > 0 ) {
        			if ( include3( x , i ) ) {
        				break;
        			}
            		x /= 10;
        		}
        	}

        }
		System.out.print( "\n" );
        sc.close();
    }
} import java.util.Scanner; Scanner java.util public class Main {

    static boolean check_num( int x ) {
    	if( ( x % 3 == 0 ) ) {
    		System.out.print( " " + x );
    		return true;
    	} else {
    		return false;
    	}
    }

    static boolean include3( int x, int i ) {
    	if ( ( x % 10 == 3 ) ) {
    		System.out.print( " " + i );
    		return true;
    	} else {
    		return false;
    	}
    }

    public static void main(String[] args) {

        int num = 0;

        Scanner sc= new Scanner( System.in );

        num = sc.nextInt();
        for ( int i = 1 ; i <= num ; i++ ) {
        	if ( check_num( i ) ) {
        		continue;
        	} else {
        		int x = i;
        		while ( x > 0 ) {
        			if ( include3( x , i ) ) {
        				break;
        			}
            		x /= 10;
        		}
        	}

        }
		System.out.print( "\n" );
        sc.close();
    }
} Main static boolean check_num( int x ) {
    	if( ( x % 3 == 0 ) ) {
    		System.out.print( " " + x );
    		return true;
    	} else {
    		return false;
    	}
    } check_num {
    	if( ( x % 3 == 0 ) ) {
    		System.out.print( " " + x );
    		return true;
    	} else {
    		return false;
    	}
    } if( ( x % 3 == 0 ) ) {
    		System.out.print( " " + x );
    		return true;
    	} else {
    		return false;
    	} ( x % 3 == 0 ) x % 3 x 3 0 {
    		System.out.print( " " + x );
    		return true;
    	} System.out.print( " " + x ) System.out.print System.out System System.out " " + x " " x return true; true {
    		return false;
    	} return false; false int x x static boolean include3( int x, int i ) {
    	if ( ( x % 10 == 3 ) ) {
    		System.out.print( " " + i );
    		return true;
    	} else {
    		return false;
    	}
    } include3 {
    	if ( ( x % 10 == 3 ) ) {
    		System.out.print( " " + i );
    		return true;
    	} else {
    		return false;
    	}
    } if ( ( x % 10 == 3 ) ) {
    		System.out.print( " " + i );
    		return true;
    	} else {
    		return false;
    	} ( x % 10 == 3 ) x % 10 x 10 3 {
    		System.out.print( " " + i );
    		return true;
    	} System.out.print( " " + i ) System.out.print System.out System System.out " " + i " " i return true; true {
    		return false;
    	} return false; false int x x int i i public static void main(String[] args) {

        int num = 0;

        Scanner sc= new Scanner( System.in );

        num = sc.nextInt();
        for ( int i = 1 ; i <= num ; i++ ) {
        	if ( check_num( i ) ) {
        		continue;
        	} else {
        		int x = i;
        		while ( x > 0 ) {
        			if ( include3( x , i ) ) {
        				break;
        			}
            		x /= 10;
        		}
        	}

        }
		System.out.print( "\n" );
        sc.close();
    } main {

        int num = 0;

        Scanner sc= new Scanner( System.in );

        num = sc.nextInt();
        for ( int i = 1 ; i <= num ; i++ ) {
        	if ( check_num( i ) ) {
        		continue;
        	} else {
        		int x = i;
        		while ( x > 0 ) {
        			if ( include3( x , i ) ) {
        				break;
        			}
            		x /= 10;
        		}
        	}

        }
		System.out.print( "\n" );
        sc.close();
    } int num = 0; num 0 Scanner sc= new Scanner( System.in ); sc new Scanner( System.in ) num = sc.nextInt() num sc.nextInt() sc.nextInt sc for ( int i = 1 ; i <= num ; i++ ) {
        	if ( check_num( i ) ) {
        		continue;
        	} else {
        		int x = i;
        		while ( x > 0 ) {
        			if ( include3( x , i ) ) {
        				break;
        			}
            		x /= 10;
        		}
        	}

        } int i = 1 ; int i = 1 ; i 1 i <= num i num i++ i++ i {
        	if ( check_num( i ) ) {
        		continue;
        	} else {
        		int x = i;
        		while ( x > 0 ) {
        			if ( include3( x , i ) ) {
        				break;
        			}
            		x /= 10;
        		}
        	}

        } {
        	if ( check_num( i ) ) {
        		continue;
        	} else {
        		int x = i;
        		while ( x > 0 ) {
        			if ( include3( x , i ) ) {
        				break;
        			}
            		x /= 10;
        		}
        	}

        } if ( check_num( i ) ) {
        		continue;
        	} else {
        		int x = i;
        		while ( x > 0 ) {
        			if ( include3( x , i ) ) {
        				break;
        			}
            		x /= 10;
        		}
        	} check_num( i ) check_num i {
        		continue;
        	} continue; {
        		int x = i;
        		while ( x > 0 ) {
        			if ( include3( x , i ) ) {
        				break;
        			}
            		x /= 10;
        		}
        	} int x = i; x i while ( x > 0 ) {
        			if ( include3( x , i ) ) {
        				break;
        			}
            		x /= 10;
        		} x > 0 x 0 {
        			if ( include3( x , i ) ) {
        				break;
        			}
            		x /= 10;
        		} if ( include3( x , i ) ) {
        				break;
        			} include3( x , i ) include3 x i {
        				break;
        			} break; x /= 10 x 10 System.out.print( "\n" ) System.out.print System.out System System.out "\n" sc.close() sc.close sc String[] args args public class Main {

    static boolean check_num( int x ) {
    	if( ( x % 3 == 0 ) ) {
    		System.out.print( " " + x );
    		return true;
    	} else {
    		return false;
    	}
    }

    static boolean include3( int x, int i ) {
    	if ( ( x % 10 == 3 ) ) {
    		System.out.print( " " + i );
    		return true;
    	} else {
    		return false;
    	}
    }

    public static void main(String[] args) {

        int num = 0;

        Scanner sc= new Scanner( System.in );

        num = sc.nextInt();
        for ( int i = 1 ; i <= num ; i++ ) {
        	if ( check_num( i ) ) {
        		continue;
        	} else {
        		int x = i;
        		while ( x > 0 ) {
        			if ( include3( x , i ) ) {
        				break;
        			}
            		x /= 10;
        		}
        	}

        }
		System.out.print( "\n" );
        sc.close();
    }
} public class Main {

    static boolean check_num( int x ) {
    	if( ( x % 3 == 0 ) ) {
    		System.out.print( " " + x );
    		return true;
    	} else {
    		return false;
    	}
    }

    static boolean include3( int x, int i ) {
    	if ( ( x % 10 == 3 ) ) {
    		System.out.print( " " + i );
    		return true;
    	} else {
    		return false;
    	}
    }

    public static void main(String[] args) {

        int num = 0;

        Scanner sc= new Scanner( System.in );

        num = sc.nextInt();
        for ( int i = 1 ; i <= num ; i++ ) {
        	if ( check_num( i ) ) {
        		continue;
        	} else {
        		int x = i;
        		while ( x > 0 ) {
        			if ( include3( x , i ) ) {
        				break;
        			}
            		x /= 10;
        		}
        	}

        }
		System.out.print( "\n" );
        sc.close();
    }
} Main
import java.util.Scanner;

public class Main {

    static boolean check_num( int x ) {
    	if( ( x % 3 == 0 ) ) {
    		System.out.print( " " + x );
    		return true;
    	} else {
    		return false;
    	}
    }

    static boolean include3( int x, int i ) {
    	if ( ( x % 10 == 3 ) ) {
    		System.out.print( " " + i );
    		return true;
    	} else {
    		return false;
    	}
    }

    public static void main(String[] args) {

        int num = 0;

        Scanner sc= new Scanner( System.in );

        num = sc.nextInt();
        for ( int i = 1 ; i <= num ; i++ ) {
        	if ( check_num( i ) ) {
        		continue;
        	} else {
        		int x = i;
        		while ( x > 0 ) {
        			if ( include3( x , i ) ) {
        				break;
        			}
            		x /= 10;
        		}
        	}

        }
		System.out.print( "\n" );
        sc.close();
    }
}
