import java.util.*;

public class Main {
    private static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        int n = sc.nextInt();
        System.out.println(calc(n));
    }
    
    private static String calc(int n) {
        StringBuilder sb = new StringBuilder();
        for (int i = 1;i <= n;i++) {
            if (
                isDiv(i) ||
                isContain(i)
            ) {
                sb.append(" ").append(i);
            }
        }
        return sb.toString();
    }
    
    private static boolean isDiv(int n) { return n%3==0; }
    private static boolean isContain(int n) {
        String s = String.valueOf(n);
        String t = "3";
        for (int i = 0;i < s.length(); i++) {
            if (s.substring(i, i+1).equals(t)) return true;
        }
        return false;
    }
} import java.util.*; util.* java public class Main {
    private static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        int n = sc.nextInt();
        System.out.println(calc(n));
    }
    
    private static String calc(int n) {
        StringBuilder sb = new StringBuilder();
        for (int i = 1;i <= n;i++) {
            if (
                isDiv(i) ||
                isContain(i)
            ) {
                sb.append(" ").append(i);
            }
        }
        return sb.toString();
    }
    
    private static boolean isDiv(int n) { return n%3==0; }
    private static boolean isContain(int n) {
        String s = String.valueOf(n);
        String t = "3";
        for (int i = 0;i < s.length(); i++) {
            if (s.substring(i, i+1).equals(t)) return true;
        }
        return false;
    }
} Main private static Scanner sc = new Scanner(System.in); sc new Scanner(System.in) public static void main(String[] args) throws Exception {
        int n = sc.nextInt();
        System.out.println(calc(n));
    } main {
        int n = sc.nextInt();
        System.out.println(calc(n));
    } int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc System.out.println(calc(n)) System.out.println System.out System System.out calc(n) calc n String[] args args private static String calc(int n) {
        StringBuilder sb = new StringBuilder();
        for (int i = 1;i <= n;i++) {
            if (
                isDiv(i) ||
                isContain(i)
            ) {
                sb.append(" ").append(i);
            }
        }
        return sb.toString();
    } calc {
        StringBuilder sb = new StringBuilder();
        for (int i = 1;i <= n;i++) {
            if (
                isDiv(i) ||
                isContain(i)
            ) {
                sb.append(" ").append(i);
            }
        }
        return sb.toString();
    } StringBuilder sb = new StringBuilder(); sb new StringBuilder() for (int i = 1;i <= n;i++) {
            if (
                isDiv(i) ||
                isContain(i)
            ) {
                sb.append(" ").append(i);
            }
        } int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
            if (
                isDiv(i) ||
                isContain(i)
            ) {
                sb.append(" ").append(i);
            }
        } {
            if (
                isDiv(i) ||
                isContain(i)
            ) {
                sb.append(" ").append(i);
            }
        } if (
                isDiv(i) ||
                isContain(i)
            ) {
                sb.append(" ").append(i);
            } isDiv(i) ||
                isContain(i) isDiv(i) isDiv i isContain(i) isContain i {
                sb.append(" ").append(i);
            } sb.append(" ").append(i) sb.append(" ").append sb.append(" ") sb.append sb " " i return sb.toString(); sb.toString() sb.toString sb int n n private static boolean isDiv(int n) { return n%3==0; } isDiv { return n%3==0; } return n%3==0; n%3==0 n%3 n 3 0 int n n private static boolean isContain(int n) {
        String s = String.valueOf(n);
        String t = "3";
        for (int i = 0;i < s.length(); i++) {
            if (s.substring(i, i+1).equals(t)) return true;
        }
        return false;
    } isContain {
        String s = String.valueOf(n);
        String t = "3";
        for (int i = 0;i < s.length(); i++) {
            if (s.substring(i, i+1).equals(t)) return true;
        }
        return false;
    } String s = String.valueOf(n); s String.valueOf(n) String.valueOf String n String t = "3"; t "3" for (int i = 0;i < s.length(); i++) {
            if (s.substring(i, i+1).equals(t)) return true;
        } int i = 0; int i = 0; i 0 i < s.length() i s.length() s.length s i++ i++ i {
            if (s.substring(i, i+1).equals(t)) return true;
        } {
            if (s.substring(i, i+1).equals(t)) return true;
        } if (s.substring(i, i+1).equals(t)) return true; s.substring(i, i+1).equals(t) s.substring(i, i+1).equals s.substring(i, i+1) s.substring s i i+1 i 1 t return true; true return false; false int n n public class Main {
    private static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        int n = sc.nextInt();
        System.out.println(calc(n));
    }
    
    private static String calc(int n) {
        StringBuilder sb = new StringBuilder();
        for (int i = 1;i <= n;i++) {
            if (
                isDiv(i) ||
                isContain(i)
            ) {
                sb.append(" ").append(i);
            }
        }
        return sb.toString();
    }
    
    private static boolean isDiv(int n) { return n%3==0; }
    private static boolean isContain(int n) {
        String s = String.valueOf(n);
        String t = "3";
        for (int i = 0;i < s.length(); i++) {
            if (s.substring(i, i+1).equals(t)) return true;
        }
        return false;
    }
} public class Main {
    private static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        int n = sc.nextInt();
        System.out.println(calc(n));
    }
    
    private static String calc(int n) {
        StringBuilder sb = new StringBuilder();
        for (int i = 1;i <= n;i++) {
            if (
                isDiv(i) ||
                isContain(i)
            ) {
                sb.append(" ").append(i);
            }
        }
        return sb.toString();
    }
    
    private static boolean isDiv(int n) { return n%3==0; }
    private static boolean isContain(int n) {
        String s = String.valueOf(n);
        String t = "3";
        for (int i = 0;i < s.length(); i++) {
            if (s.substring(i, i+1).equals(t)) return true;
        }
        return false;
    }
} Main
import java.util.*;

public class Main {
    private static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        int n = sc.nextInt();
        System.out.println(calc(n));
    }
    
    private static String calc(int n) {
        StringBuilder sb = new StringBuilder();
        for (int i = 1;i <= n;i++) {
            if (
                isDiv(i) ||
                isContain(i)
            ) {
                sb.append(" ").append(i);
            }
        }
        return sb.toString();
    }
    
    private static boolean isDiv(int n) { return n%3==0; }
    private static boolean isContain(int n) {
        String s = String.valueOf(n);
        String t = "3";
        for (int i = 0;i < s.length(); i++) {
            if (s.substring(i, i+1).equals(t)) return true;
        }
        return false;
    }
}