import java.util.Scanner;

public class Main {
    public static Scanner sc = new Scanner(System.in);
    public static StringBuilder sb = new StringBuilder();
    public static void main(String[] args) throws Exception {
        int n = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            if (i%3 == 0) {
                sb.append(" ").append(i);
            } else {
                calc(i, i);
            }
        }
//        sb.delete(sb.length()-1, sb.length());
        System.out.println(sb.toString());
    }
    
    public static void calc(int n, int i) {
        if (n%10 == 3) {
            sb.append(" ").append(i);
            return;
        } else if (n/10 > 0) {
            calc(n/10, i);
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static Scanner sc = new Scanner(System.in);
    public static StringBuilder sb = new StringBuilder();
    public static void main(String[] args) throws Exception {
        int n = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            if (i%3 == 0) {
                sb.append(" ").append(i);
            } else {
                calc(i, i);
            }
        }
//        sb.delete(sb.length()-1, sb.length());
        System.out.println(sb.toString());
    }
    
    public static void calc(int n, int i) {
        if (n%10 == 3) {
            sb.append(" ").append(i);
            return;
        } else if (n/10 > 0) {
            calc(n/10, i);
        }
    }
} Main public static Scanner sc = new Scanner(System.in); sc new Scanner(System.in) public static StringBuilder sb = new StringBuilder(); sb new StringBuilder() public static void main(String[] args) throws Exception {
        int n = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            if (i%3 == 0) {
                sb.append(" ").append(i);
            } else {
                calc(i, i);
            }
        }
//        sb.delete(sb.length()-1, sb.length());
        System.out.println(sb.toString());
    } main {
        int n = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            if (i%3 == 0) {
                sb.append(" ").append(i);
            } else {
                calc(i, i);
            }
        }
//        sb.delete(sb.length()-1, sb.length());
        System.out.println(sb.toString());
    } int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc for (int i = 1; i <= n; i++) {
            if (i%3 == 0) {
                sb.append(" ").append(i);
            } else {
                calc(i, i);
            }
        } int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
            if (i%3 == 0) {
                sb.append(" ").append(i);
            } else {
                calc(i, i);
            }
        } {
            if (i%3 == 0) {
                sb.append(" ").append(i);
            } else {
                calc(i, i);
            }
        } if (i%3 == 0) {
                sb.append(" ").append(i);
            } else {
                calc(i, i);
            } i%3 == 0 i%3 i 3 0 {
                sb.append(" ").append(i);
            } sb.append(" ").append(i) sb.append(" ").append sb.append(" ") sb.append sb " " i {
                calc(i, i);
            } calc(i, i) calc i i System.out.println(sb.toString()) System.out.println System.out System System.out sb.toString() sb.toString sb String[] args args public static void calc(int n, int i) {
        if (n%10 == 3) {
            sb.append(" ").append(i);
            return;
        } else if (n/10 > 0) {
            calc(n/10, i);
        }
    } calc {
        if (n%10 == 3) {
            sb.append(" ").append(i);
            return;
        } else if (n/10 > 0) {
            calc(n/10, i);
        }
    } if (n%10 == 3) {
            sb.append(" ").append(i);
            return;
        } else if (n/10 > 0) {
            calc(n/10, i);
        } n%10 == 3 n%10 n 10 3 {
            sb.append(" ").append(i);
            return;
        } sb.append(" ").append(i) sb.append(" ").append sb.append(" ") sb.append sb " " i return; if (n/10 > 0) {
            calc(n/10, i);
        } n/10 > 0 n/10 n 10 0 {
            calc(n/10, i);
        } calc(n/10, i) calc n/10 n 10 i int n n int i i public class Main {
    public static Scanner sc = new Scanner(System.in);
    public static StringBuilder sb = new StringBuilder();
    public static void main(String[] args) throws Exception {
        int n = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            if (i%3 == 0) {
                sb.append(" ").append(i);
            } else {
                calc(i, i);
            }
        }
//        sb.delete(sb.length()-1, sb.length());
        System.out.println(sb.toString());
    }
    
    public static void calc(int n, int i) {
        if (n%10 == 3) {
            sb.append(" ").append(i);
            return;
        } else if (n/10 > 0) {
            calc(n/10, i);
        }
    }
} public class Main {
    public static Scanner sc = new Scanner(System.in);
    public static StringBuilder sb = new StringBuilder();
    public static void main(String[] args) throws Exception {
        int n = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            if (i%3 == 0) {
                sb.append(" ").append(i);
            } else {
                calc(i, i);
            }
        }
//        sb.delete(sb.length()-1, sb.length());
        System.out.println(sb.toString());
    }
    
    public static void calc(int n, int i) {
        if (n%10 == 3) {
            sb.append(" ").append(i);
            return;
        } else if (n/10 > 0) {
            calc(n/10, i);
        }
    }
} Main
import java.util.Scanner;

public class Main {
    public static Scanner sc = new Scanner(System.in);
    public static StringBuilder sb = new StringBuilder();
    public static void main(String[] args) throws Exception {
        int n = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            if (i%3 == 0) {
                sb.append(" ").append(i);
            } else {
                calc(i, i);
            }
        }
//        sb.delete(sb.length()-1, sb.length());
        System.out.println(sb.toString());
    }
    
    public static void calc(int n, int i) {
        if (n%10 == 3) {
            sb.append(" ").append(i);
            return;
        } else if (n/10 > 0) {
            calc(n/10, i);
        }
    }
}