import java.util.Scanner;
 
public class Main {
    public static void main(String args[]) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt(); //n????????\?????????????????????
        StringBuilder NewBuilder = new StringBuilder(); 
        
        int x = 0;
        
        //?????????????????????????????????????????????
        for (int j = 3; j <= n; j++) {
            if (j % 3 == 0) {
            	NewBuilder .append(" " + j);
            } else {
                x = j;
                while (x != 0) {
                    if (x % 10 == 3) {
                    	NewBuilder .append(" " + j);
                        break;
                    } else {
                        x = x / 10;
                    }
                }
            }
 
        }
        //???????????????????????§???
        System.out.println(NewBuilder );
        
        sc.close();
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String args[]) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt(); //n????????\?????????????????????
        StringBuilder NewBuilder = new StringBuilder(); 
        
        int x = 0;
        
        //?????????????????????????????????????????????
        for (int j = 3; j <= n; j++) {
            if (j % 3 == 0) {
            	NewBuilder .append(" " + j);
            } else {
                x = j;
                while (x != 0) {
                    if (x % 10 == 3) {
                    	NewBuilder .append(" " + j);
                        break;
                    } else {
                        x = x / 10;
                    }
                }
            }
 
        }
        //???????????????????????§???
        System.out.println(NewBuilder );
        
        sc.close();
    }
} Main public static void main(String args[]) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt(); //n????????\?????????????????????
        StringBuilder NewBuilder = new StringBuilder(); 
        
        int x = 0;
        
        //?????????????????????????????????????????????
        for (int j = 3; j <= n; j++) {
            if (j % 3 == 0) {
            	NewBuilder .append(" " + j);
            } else {
                x = j;
                while (x != 0) {
                    if (x % 10 == 3) {
                    	NewBuilder .append(" " + j);
                        break;
                    } else {
                        x = x / 10;
                    }
                }
            }
 
        }
        //???????????????????????§???
        System.out.println(NewBuilder );
        
        sc.close();
    } main {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt(); //n????????\?????????????????????
        StringBuilder NewBuilder = new StringBuilder(); 
        
        int x = 0;
        
        //?????????????????????????????????????????????
        for (int j = 3; j <= n; j++) {
            if (j % 3 == 0) {
            	NewBuilder .append(" " + j);
            } else {
                x = j;
                while (x != 0) {
                    if (x % 10 == 3) {
                    	NewBuilder .append(" " + j);
                        break;
                    } else {
                        x = x / 10;
                    }
                }
            }
 
        }
        //???????????????????????§???
        System.out.println(NewBuilder );
        
        sc.close();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc StringBuilder NewBuilder = new StringBuilder(); NewBuilder new StringBuilder() int x = 0; x 0 for (int j = 3; j <= n; j++) {
            if (j % 3 == 0) {
            	NewBuilder .append(" " + j);
            } else {
                x = j;
                while (x != 0) {
                    if (x % 10 == 3) {
                    	NewBuilder .append(" " + j);
                        break;
                    } else {
                        x = x / 10;
                    }
                }
            }
 
        } int j = 3; int j = 3; j 3 j <= n j n j++ j++ j {
            if (j % 3 == 0) {
            	NewBuilder .append(" " + j);
            } else {
                x = j;
                while (x != 0) {
                    if (x % 10 == 3) {
                    	NewBuilder .append(" " + j);
                        break;
                    } else {
                        x = x / 10;
                    }
                }
            }
 
        } {
            if (j % 3 == 0) {
            	NewBuilder .append(" " + j);
            } else {
                x = j;
                while (x != 0) {
                    if (x % 10 == 3) {
                    	NewBuilder .append(" " + j);
                        break;
                    } else {
                        x = x / 10;
                    }
                }
            }
 
        } if (j % 3 == 0) {
            	NewBuilder .append(" " + j);
            } else {
                x = j;
                while (x != 0) {
                    if (x % 10 == 3) {
                    	NewBuilder .append(" " + j);
                        break;
                    } else {
                        x = x / 10;
                    }
                }
            } j % 3 == 0 j % 3 j 3 0 {
            	NewBuilder .append(" " + j);
            } NewBuilder .append(" " + j) NewBuilder .append NewBuilder " " + j " " j {
                x = j;
                while (x != 0) {
                    if (x % 10 == 3) {
                    	NewBuilder .append(" " + j);
                        break;
                    } else {
                        x = x / 10;
                    }
                }
            } x = j x j while (x != 0) {
                    if (x % 10 == 3) {
                    	NewBuilder .append(" " + j);
                        break;
                    } else {
                        x = x / 10;
                    }
                } x != 0 x 0 {
                    if (x % 10 == 3) {
                    	NewBuilder .append(" " + j);
                        break;
                    } else {
                        x = x / 10;
                    }
                } if (x % 10 == 3) {
                    	NewBuilder .append(" " + j);
                        break;
                    } else {
                        x = x / 10;
                    } x % 10 == 3 x % 10 x 10 3 {
                    	NewBuilder .append(" " + j);
                        break;
                    } NewBuilder .append(" " + j) NewBuilder .append NewBuilder " " + j " " j break; {
                        x = x / 10;
                    } x = x / 10 x x / 10 x 10 System.out.println(NewBuilder ) System.out.println System.out System System.out NewBuilder sc.close() sc.close sc String args[] args public class Main {
    public static void main(String args[]) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt(); //n????????\?????????????????????
        StringBuilder NewBuilder = new StringBuilder(); 
        
        int x = 0;
        
        //?????????????????????????????????????????????
        for (int j = 3; j <= n; j++) {
            if (j % 3 == 0) {
            	NewBuilder .append(" " + j);
            } else {
                x = j;
                while (x != 0) {
                    if (x % 10 == 3) {
                    	NewBuilder .append(" " + j);
                        break;
                    } else {
                        x = x / 10;
                    }
                }
            }
 
        }
        //???????????????????????§???
        System.out.println(NewBuilder );
        
        sc.close();
    }
} public class Main {
    public static void main(String args[]) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt(); //n????????\?????????????????????
        StringBuilder NewBuilder = new StringBuilder(); 
        
        int x = 0;
        
        //?????????????????????????????????????????????
        for (int j = 3; j <= n; j++) {
            if (j % 3 == 0) {
            	NewBuilder .append(" " + j);
            } else {
                x = j;
                while (x != 0) {
                    if (x % 10 == 3) {
                    	NewBuilder .append(" " + j);
                        break;
                    } else {
                        x = x / 10;
                    }
                }
            }
 
        }
        //???????????????????????§???
        System.out.println(NewBuilder );
        
        sc.close();
    }
} Main
import java.util.Scanner;
 
public class Main {
    public static void main(String args[]) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt(); //n????????\?????????????????????
        StringBuilder NewBuilder = new StringBuilder(); 
        
        int x = 0;
        
        //?????????????????????????????????????????????
        for (int j = 3; j <= n; j++) {
            if (j % 3 == 0) {
            	NewBuilder .append(" " + j);
            } else {
                x = j;
                while (x != 0) {
                    if (x % 10 == 3) {
                    	NewBuilder .append(" " + j);
                        break;
                    } else {
                        x = x / 10;
                    }
                }
            }
 
        }
        //???????????????????????§???
        System.out.println(NewBuilder );
        
        sc.close();
    }
}