import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * @param args
 */
public class Main {
    static final String HASHMARK = "#";
    static final String DOTMARK  = ".";
    static final String SPACE    = " ";
    
    public static void main(String[] args) {
        try {
            BufferedReader stdReader = new BufferedReader(
                    new InputStreamReader(System.in));
            
            String sStr;
            while ((sStr = stdReader.readLine()) != null) {
                String[] inputs = sStr.split(" ");
                
                int n = Integer.valueOf(inputs[0]);
                call(n);
            }
            stdReader.close();
        } catch (Exception e) {
            System.exit(-1);
        }
    }
    
    // void call(int n){
    // int i = 1;
    // CHECK_NUM:
    // int x = i;
    // if ( x % 3 == 0 ){
    // cout << " " << i;
    // goto END_CHECK_NUM;
    // }
    // INCLUDE3:
    // if ( x % 10 == 3 ){
    // cout << " " << i;
    // goto END_CHECK_NUM;
    // }
    // x /= 10;
    // if ( x ) goto INCLUDE3;
    // END_CHECK_NUM:
    // if ( ++i <= n ) goto CHECK_NUM;
    //
    // cout << endl;
    // }
    
    private static void call(int n) {
        int i = 1;
        boolean flg = false;
        
        while (true) {
            // CHECK_NUM:
            int x = i;
            if (x % 3 == 0) {
                System.out.print(SPACE + i);
                if (++i <= n) {
                    continue;
                } else {
                    break;
                }
            }
            
            // INCLUDE3:
            do {
                if (x % 10 == 3) {
                    System.out.print(SPACE + i);
                    if (++i <= n) {
                        flg = true;
                        break;
                    }
                }
                x /= 10;
            } while (0 != x );
            if (flg) {
                flg = false;
                continue;
            }
            if (++i <= n) {
                continue;
            } else {
                break;
            }
        }
        
        System.out.println();
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
    static final String HASHMARK = "#";
    static final String DOTMARK  = ".";
    static final String SPACE    = " ";
    
    public static void main(String[] args) {
        try {
            BufferedReader stdReader = new BufferedReader(
                    new InputStreamReader(System.in));
            
            String sStr;
            while ((sStr = stdReader.readLine()) != null) {
                String[] inputs = sStr.split(" ");
                
                int n = Integer.valueOf(inputs[0]);
                call(n);
            }
            stdReader.close();
        } catch (Exception e) {
            System.exit(-1);
        }
    }
    
    // void call(int n){
    // int i = 1;
    // CHECK_NUM:
    // int x = i;
    // if ( x % 3 == 0 ){
    // cout << " " << i;
    // goto END_CHECK_NUM;
    // }
    // INCLUDE3:
    // if ( x % 10 == 3 ){
    // cout << " " << i;
    // goto END_CHECK_NUM;
    // }
    // x /= 10;
    // if ( x ) goto INCLUDE3;
    // END_CHECK_NUM:
    // if ( ++i <= n ) goto CHECK_NUM;
    //
    // cout << endl;
    // }
    
    private static void call(int n) {
        int i = 1;
        boolean flg = false;
        
        while (true) {
            // CHECK_NUM:
            int x = i;
            if (x % 3 == 0) {
                System.out.print(SPACE + i);
                if (++i <= n) {
                    continue;
                } else {
                    break;
                }
            }
            
            // INCLUDE3:
            do {
                if (x % 10 == 3) {
                    System.out.print(SPACE + i);
                    if (++i <= n) {
                        flg = true;
                        break;
                    }
                }
                x /= 10;
            } while (0 != x );
            if (flg) {
                flg = false;
                continue;
            }
            if (++i <= n) {
                continue;
            } else {
                break;
            }
        }
        
        System.out.println();
    }
} Main static final String HASHMARK = "#"; HASHMARK "#" static final String DOTMARK  = "."; DOTMARK "." static final String SPACE    = " "; SPACE " " public static void main(String[] args) {
        try {
            BufferedReader stdReader = new BufferedReader(
                    new InputStreamReader(System.in));
            
            String sStr;
            while ((sStr = stdReader.readLine()) != null) {
                String[] inputs = sStr.split(" ");
                
                int n = Integer.valueOf(inputs[0]);
                call(n);
            }
            stdReader.close();
        } catch (Exception e) {
            System.exit(-1);
        }
    } main {
        try {
            BufferedReader stdReader = new BufferedReader(
                    new InputStreamReader(System.in));
            
            String sStr;
            while ((sStr = stdReader.readLine()) != null) {
                String[] inputs = sStr.split(" ");
                
                int n = Integer.valueOf(inputs[0]);
                call(n);
            }
            stdReader.close();
        } catch (Exception e) {
            System.exit(-1);
        }
    } try {
            BufferedReader stdReader = new BufferedReader(
                    new InputStreamReader(System.in));
            
            String sStr;
            while ((sStr = stdReader.readLine()) != null) {
                String[] inputs = sStr.split(" ");
                
                int n = Integer.valueOf(inputs[0]);
                call(n);
            }
            stdReader.close();
        } catch (Exception e) {
            System.exit(-1);
        } catch (Exception e) {
            System.exit(-1);
        } Exception e {
            System.exit(-1);
        } System.exit(-1) System.exit System -1 1 {
            BufferedReader stdReader = new BufferedReader(
                    new InputStreamReader(System.in));
            
            String sStr;
            while ((sStr = stdReader.readLine()) != null) {
                String[] inputs = sStr.split(" ");
                
                int n = Integer.valueOf(inputs[0]);
                call(n);
            }
            stdReader.close();
        } BufferedReader stdReader = new BufferedReader(
                    new InputStreamReader(System.in)); stdReader new BufferedReader(
                    new InputStreamReader(System.in)) String sStr; sStr while ((sStr = stdReader.readLine()) != null) {
                String[] inputs = sStr.split(" ");
                
                int n = Integer.valueOf(inputs[0]);
                call(n);
            } (sStr = stdReader.readLine()) != null (sStr = stdReader.readLine()) sStr stdReader.readLine() stdReader.readLine stdReader null {
                String[] inputs = sStr.split(" ");
                
                int n = Integer.valueOf(inputs[0]);
                call(n);
            } String[] inputs = sStr.split(" "); inputs sStr.split(" ") sStr.split sStr " " int n = Integer.valueOf(inputs[0]); n Integer.valueOf(inputs[0]) Integer.valueOf Integer inputs[0] inputs 0 call(n) call n stdReader.close() stdReader.close stdReader String[] args args private static void call(int n) {
        int i = 1;
        boolean flg = false;
        
        while (true) {
            // CHECK_NUM:
            int x = i;
            if (x % 3 == 0) {
                System.out.print(SPACE + i);
                if (++i <= n) {
                    continue;
                } else {
                    break;
                }
            }
            
            // INCLUDE3:
            do {
                if (x % 10 == 3) {
                    System.out.print(SPACE + i);
                    if (++i <= n) {
                        flg = true;
                        break;
                    }
                }
                x /= 10;
            } while (0 != x );
            if (flg) {
                flg = false;
                continue;
            }
            if (++i <= n) {
                continue;
            } else {
                break;
            }
        }
        
        System.out.println();
    } call {
        int i = 1;
        boolean flg = false;
        
        while (true) {
            // CHECK_NUM:
            int x = i;
            if (x % 3 == 0) {
                System.out.print(SPACE + i);
                if (++i <= n) {
                    continue;
                } else {
                    break;
                }
            }
            
            // INCLUDE3:
            do {
                if (x % 10 == 3) {
                    System.out.print(SPACE + i);
                    if (++i <= n) {
                        flg = true;
                        break;
                    }
                }
                x /= 10;
            } while (0 != x );
            if (flg) {
                flg = false;
                continue;
            }
            if (++i <= n) {
                continue;
            } else {
                break;
            }
        }
        
        System.out.println();
    } int i = 1; i 1 boolean flg = false; flg false while (true) {
            // CHECK_NUM:
            int x = i;
            if (x % 3 == 0) {
                System.out.print(SPACE + i);
                if (++i <= n) {
                    continue;
                } else {
                    break;
                }
            }
            
            // INCLUDE3:
            do {
                if (x % 10 == 3) {
                    System.out.print(SPACE + i);
                    if (++i <= n) {
                        flg = true;
                        break;
                    }
                }
                x /= 10;
            } while (0 != x );
            if (flg) {
                flg = false;
                continue;
            }
            if (++i <= n) {
                continue;
            } else {
                break;
            }
        } true {
            // CHECK_NUM:
            int x = i;
            if (x % 3 == 0) {
                System.out.print(SPACE + i);
                if (++i <= n) {
                    continue;
                } else {
                    break;
                }
            }
            
            // INCLUDE3:
            do {
                if (x % 10 == 3) {
                    System.out.print(SPACE + i);
                    if (++i <= n) {
                        flg = true;
                        break;
                    }
                }
                x /= 10;
            } while (0 != x );
            if (flg) {
                flg = false;
                continue;
            }
            if (++i <= n) {
                continue;
            } else {
                break;
            }
        } int x = i; x i if (x % 3 == 0) {
                System.out.print(SPACE + i);
                if (++i <= n) {
                    continue;
                } else {
                    break;
                }
            } x % 3 == 0 x % 3 x 3 0 {
                System.out.print(SPACE + i);
                if (++i <= n) {
                    continue;
                } else {
                    break;
                }
            } System.out.print(SPACE + i) System.out.print System.out System System.out SPACE + i SPACE i if (++i <= n) {
                    continue;
                } else {
                    break;
                } ++i <= n ++i i n {
                    continue;
                } continue; {
                    break;
                } break; do {
                if (x % 10 == 3) {
                    System.out.print(SPACE + i);
                    if (++i <= n) {
                        flg = true;
                        break;
                    }
                }
                x /= 10;
            } while (0 != x ); 0 != x 0 x {
                if (x % 10 == 3) {
                    System.out.print(SPACE + i);
                    if (++i <= n) {
                        flg = true;
                        break;
                    }
                }
                x /= 10;
            } if (x % 10 == 3) {
                    System.out.print(SPACE + i);
                    if (++i <= n) {
                        flg = true;
                        break;
                    }
                } x % 10 == 3 x % 10 x 10 3 {
                    System.out.print(SPACE + i);
                    if (++i <= n) {
                        flg = true;
                        break;
                    }
                } System.out.print(SPACE + i) System.out.print System.out System System.out SPACE + i SPACE i if (++i <= n) {
                        flg = true;
                        break;
                    } ++i <= n ++i i n {
                        flg = true;
                        break;
                    } flg = true flg true break; x /= 10 x 10 if (flg) {
                flg = false;
                continue;
            } flg {
                flg = false;
                continue;
            } flg = false flg false continue; if (++i <= n) {
                continue;
            } else {
                break;
            } ++i <= n ++i i n {
                continue;
            } continue; {
                break;
            } break; System.out.println() System.out.println System.out System System.out int n n public class Main {
    static final String HASHMARK = "#";
    static final String DOTMARK  = ".";
    static final String SPACE    = " ";
    
    public static void main(String[] args) {
        try {
            BufferedReader stdReader = new BufferedReader(
                    new InputStreamReader(System.in));
            
            String sStr;
            while ((sStr = stdReader.readLine()) != null) {
                String[] inputs = sStr.split(" ");
                
                int n = Integer.valueOf(inputs[0]);
                call(n);
            }
            stdReader.close();
        } catch (Exception e) {
            System.exit(-1);
        }
    }
    
    // void call(int n){
    // int i = 1;
    // CHECK_NUM:
    // int x = i;
    // if ( x % 3 == 0 ){
    // cout << " " << i;
    // goto END_CHECK_NUM;
    // }
    // INCLUDE3:
    // if ( x % 10 == 3 ){
    // cout << " " << i;
    // goto END_CHECK_NUM;
    // }
    // x /= 10;
    // if ( x ) goto INCLUDE3;
    // END_CHECK_NUM:
    // if ( ++i <= n ) goto CHECK_NUM;
    //
    // cout << endl;
    // }
    
    private static void call(int n) {
        int i = 1;
        boolean flg = false;
        
        while (true) {
            // CHECK_NUM:
            int x = i;
            if (x % 3 == 0) {
                System.out.print(SPACE + i);
                if (++i <= n) {
                    continue;
                } else {
                    break;
                }
            }
            
            // INCLUDE3:
            do {
                if (x % 10 == 3) {
                    System.out.print(SPACE + i);
                    if (++i <= n) {
                        flg = true;
                        break;
                    }
                }
                x /= 10;
            } while (0 != x );
            if (flg) {
                flg = false;
                continue;
            }
            if (++i <= n) {
                continue;
            } else {
                break;
            }
        }
        
        System.out.println();
    }
} public class Main {
    static final String HASHMARK = "#";
    static final String DOTMARK  = ".";
    static final String SPACE    = " ";
    
    public static void main(String[] args) {
        try {
            BufferedReader stdReader = new BufferedReader(
                    new InputStreamReader(System.in));
            
            String sStr;
            while ((sStr = stdReader.readLine()) != null) {
                String[] inputs = sStr.split(" ");
                
                int n = Integer.valueOf(inputs[0]);
                call(n);
            }
            stdReader.close();
        } catch (Exception e) {
            System.exit(-1);
        }
    }
    
    // void call(int n){
    // int i = 1;
    // CHECK_NUM:
    // int x = i;
    // if ( x % 3 == 0 ){
    // cout << " " << i;
    // goto END_CHECK_NUM;
    // }
    // INCLUDE3:
    // if ( x % 10 == 3 ){
    // cout << " " << i;
    // goto END_CHECK_NUM;
    // }
    // x /= 10;
    // if ( x ) goto INCLUDE3;
    // END_CHECK_NUM:
    // if ( ++i <= n ) goto CHECK_NUM;
    //
    // cout << endl;
    // }
    
    private static void call(int n) {
        int i = 1;
        boolean flg = false;
        
        while (true) {
            // CHECK_NUM:
            int x = i;
            if (x % 3 == 0) {
                System.out.print(SPACE + i);
                if (++i <= n) {
                    continue;
                } else {
                    break;
                }
            }
            
            // INCLUDE3:
            do {
                if (x % 10 == 3) {
                    System.out.print(SPACE + i);
                    if (++i <= n) {
                        flg = true;
                        break;
                    }
                }
                x /= 10;
            } while (0 != x );
            if (flg) {
                flg = false;
                continue;
            }
            if (++i <= n) {
                continue;
            } else {
                break;
            }
        }
        
        System.out.println();
    }
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * @param args
 */
public class Main {
    static final String HASHMARK = "#";
    static final String DOTMARK  = ".";
    static final String SPACE    = " ";
    
    public static void main(String[] args) {
        try {
            BufferedReader stdReader = new BufferedReader(
                    new InputStreamReader(System.in));
            
            String sStr;
            while ((sStr = stdReader.readLine()) != null) {
                String[] inputs = sStr.split(" ");
                
                int n = Integer.valueOf(inputs[0]);
                call(n);
            }
            stdReader.close();
        } catch (Exception e) {
            System.exit(-1);
        }
    }
    
    // void call(int n){
    // int i = 1;
    // CHECK_NUM:
    // int x = i;
    // if ( x % 3 == 0 ){
    // cout << " " << i;
    // goto END_CHECK_NUM;
    // }
    // INCLUDE3:
    // if ( x % 10 == 3 ){
    // cout << " " << i;
    // goto END_CHECK_NUM;
    // }
    // x /= 10;
    // if ( x ) goto INCLUDE3;
    // END_CHECK_NUM:
    // if ( ++i <= n ) goto CHECK_NUM;
    //
    // cout << endl;
    // }
    
    private static void call(int n) {
        int i = 1;
        boolean flg = false;
        
        while (true) {
            // CHECK_NUM:
            int x = i;
            if (x % 3 == 0) {
                System.out.print(SPACE + i);
                if (++i <= n) {
                    continue;
                } else {
                    break;
                }
            }
            
            // INCLUDE3:
            do {
                if (x % 10 == 3) {
                    System.out.print(SPACE + i);
                    if (++i <= n) {
                        flg = true;
                        break;
                    }
                }
                x /= 10;
            } while (0 != x );
            if (flg) {
                flg = false;
                continue;
            }
            if (++i <= n) {
                continue;
            } else {
                break;
            }
        }
        
        System.out.println();
    }
}