import java.util.*;

public class Main {
    private static final Scanner scn = new Scanner(System.in);
    
    public static void main(String[] args) {
        for(int i = 1, n = scn.nextInt(); i <= n; i++) {
            if(call(i)) {
                System.out.print(" " + i);
            }
        }
        System.out.println();
    }
    
    private static boolean call(int x) {
        boolean rslt = false;
        if(x % 3 == 0) {
            rslt = true;
        }
        for(; x > 0; x /= 10) {
            if(x % 10 == 3) {
                rslt = true;
                break;
            }
        }
        return rslt;
    }
} import java.util.*; util.* java public class Main {
    private static final Scanner scn = new Scanner(System.in);
    
    public static void main(String[] args) {
        for(int i = 1, n = scn.nextInt(); i <= n; i++) {
            if(call(i)) {
                System.out.print(" " + i);
            }
        }
        System.out.println();
    }
    
    private static boolean call(int x) {
        boolean rslt = false;
        if(x % 3 == 0) {
            rslt = true;
        }
        for(; x > 0; x /= 10) {
            if(x % 10 == 3) {
                rslt = true;
                break;
            }
        }
        return rslt;
    }
} Main private static final Scanner scn = new Scanner(System.in); scn new Scanner(System.in) public static void main(String[] args) {
        for(int i = 1, n = scn.nextInt(); i <= n; i++) {
            if(call(i)) {
                System.out.print(" " + i);
            }
        }
        System.out.println();
    } main {
        for(int i = 1, n = scn.nextInt(); i <= n; i++) {
            if(call(i)) {
                System.out.print(" " + i);
            }
        }
        System.out.println();
    } for(int i = 1, n = scn.nextInt(); i <= n; i++) {
            if(call(i)) {
                System.out.print(" " + i);
            }
        } int i = 1, n = scn.nextInt(); int i = 1 i 1 n = scn.nextInt(); n scn.nextInt() scn.nextInt scn i <= n i n i++ i++ i {
            if(call(i)) {
                System.out.print(" " + i);
            }
        } {
            if(call(i)) {
                System.out.print(" " + i);
            }
        } if(call(i)) {
                System.out.print(" " + i);
            } call(i) call i {
                System.out.print(" " + i);
            } System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i System.out.println() System.out.println System.out System System.out String[] args args private static boolean call(int x) {
        boolean rslt = false;
        if(x % 3 == 0) {
            rslt = true;
        }
        for(; x > 0; x /= 10) {
            if(x % 10 == 3) {
                rslt = true;
                break;
            }
        }
        return rslt;
    } call {
        boolean rslt = false;
        if(x % 3 == 0) {
            rslt = true;
        }
        for(; x > 0; x /= 10) {
            if(x % 10 == 3) {
                rslt = true;
                break;
            }
        }
        return rslt;
    } boolean rslt = false; rslt false if(x % 3 == 0) {
            rslt = true;
        } x % 3 == 0 x % 3 x 3 0 {
            rslt = true;
        } rslt = true rslt true for(; x > 0; x /= 10) {
            if(x % 10 == 3) {
                rslt = true;
                break;
            }
        } ; x > 0 x 0 x /= 10 x /= 10 x 10 {
            if(x % 10 == 3) {
                rslt = true;
                break;
            }
        } {
            if(x % 10 == 3) {
                rslt = true;
                break;
            }
        } if(x % 10 == 3) {
                rslt = true;
                break;
            } x % 10 == 3 x % 10 x 10 3 {
                rslt = true;
                break;
            } rslt = true rslt true break; return rslt; rslt int x x public class Main {
    private static final Scanner scn = new Scanner(System.in);
    
    public static void main(String[] args) {
        for(int i = 1, n = scn.nextInt(); i <= n; i++) {
            if(call(i)) {
                System.out.print(" " + i);
            }
        }
        System.out.println();
    }
    
    private static boolean call(int x) {
        boolean rslt = false;
        if(x % 3 == 0) {
            rslt = true;
        }
        for(; x > 0; x /= 10) {
            if(x % 10 == 3) {
                rslt = true;
                break;
            }
        }
        return rslt;
    }
} public class Main {
    private static final Scanner scn = new Scanner(System.in);
    
    public static void main(String[] args) {
        for(int i = 1, n = scn.nextInt(); i <= n; i++) {
            if(call(i)) {
                System.out.print(" " + i);
            }
        }
        System.out.println();
    }
    
    private static boolean call(int x) {
        boolean rslt = false;
        if(x % 3 == 0) {
            rslt = true;
        }
        for(; x > 0; x /= 10) {
            if(x % 10 == 3) {
                rslt = true;
                break;
            }
        }
        return rslt;
    }
} Main
import java.util.*;

public class Main {
    private static final Scanner scn = new Scanner(System.in);
    
    public static void main(String[] args) {
        for(int i = 1, n = scn.nextInt(); i <= n; i++) {
            if(call(i)) {
                System.out.print(" " + i);
            }
        }
        System.out.println();
    }
    
    private static boolean call(int x) {
        boolean rslt = false;
        if(x % 3 == 0) {
            rslt = true;
        }
        for(; x > 0; x /= 10) {
            if(x % 10 == 3) {
                rslt = true;
                break;
            }
        }
        return rslt;
    }
}