public class Main {

    protected static String calc(String input) {
        final int data = Integer.parseInt(input);

        StringBuilder sb = new StringBuilder();

        for (int i = 1; i <= data; i++) {
            if (check(i)) {
                sb.append(' ');
                sb.append(i);
            }
        }

        return sb.toString();
    }

    static boolean check(int x) {
        if (x % 3 == 0) {
            return true;
        }
        return check0(x);
    }

    static boolean check0(int x) {
        if (x % 10 == 3) {
            return true;
        }
        x /= 10;
        if (x > 0) {
            return check0(x);
        }
        return false;
    }

    public static void main(String[] args) {
        final String line = readLine();
        System.out.println(calc(line));
    }

    private static String readLine() {
        java.util.Scanner s = null;
        try {
            s = new java.util.Scanner(System.in);
            return s.nextLine();
        } finally {
            if (s != null) {
                s.close();
            }
        }
    }
} public class Main {

    protected static String calc(String input) {
        final int data = Integer.parseInt(input);

        StringBuilder sb = new StringBuilder();

        for (int i = 1; i <= data; i++) {
            if (check(i)) {
                sb.append(' ');
                sb.append(i);
            }
        }

        return sb.toString();
    }

    static boolean check(int x) {
        if (x % 3 == 0) {
            return true;
        }
        return check0(x);
    }

    static boolean check0(int x) {
        if (x % 10 == 3) {
            return true;
        }
        x /= 10;
        if (x > 0) {
            return check0(x);
        }
        return false;
    }

    public static void main(String[] args) {
        final String line = readLine();
        System.out.println(calc(line));
    }

    private static String readLine() {
        java.util.Scanner s = null;
        try {
            s = new java.util.Scanner(System.in);
            return s.nextLine();
        } finally {
            if (s != null) {
                s.close();
            }
        }
    }
} Main protected static String calc(String input) {
        final int data = Integer.parseInt(input);

        StringBuilder sb = new StringBuilder();

        for (int i = 1; i <= data; i++) {
            if (check(i)) {
                sb.append(' ');
                sb.append(i);
            }
        }

        return sb.toString();
    } calc {
        final int data = Integer.parseInt(input);

        StringBuilder sb = new StringBuilder();

        for (int i = 1; i <= data; i++) {
            if (check(i)) {
                sb.append(' ');
                sb.append(i);
            }
        }

        return sb.toString();
    } final int data = Integer.parseInt(input); data Integer.parseInt(input) Integer.parseInt Integer input StringBuilder sb = new StringBuilder(); sb new StringBuilder() for (int i = 1; i <= data; i++) {
            if (check(i)) {
                sb.append(' ');
                sb.append(i);
            }
        } int i = 1; int i = 1; i 1 i <= data i data i++ i++ i {
            if (check(i)) {
                sb.append(' ');
                sb.append(i);
            }
        } {
            if (check(i)) {
                sb.append(' ');
                sb.append(i);
            }
        } if (check(i)) {
                sb.append(' ');
                sb.append(i);
            } check(i) check i {
                sb.append(' ');
                sb.append(i);
            } sb.append(' ') sb.append sb ' ' sb.append(i) sb.append sb i return sb.toString(); sb.toString() sb.toString sb String input input static boolean check(int x) {
        if (x % 3 == 0) {
            return true;
        }
        return check0(x);
    } check {
        if (x % 3 == 0) {
            return true;
        }
        return check0(x);
    } if (x % 3 == 0) {
            return true;
        } x % 3 == 0 x % 3 x 3 0 {
            return true;
        } return true; true return check0(x); check0(x) check0 x int x x static boolean check0(int x) {
        if (x % 10 == 3) {
            return true;
        }
        x /= 10;
        if (x > 0) {
            return check0(x);
        }
        return false;
    } check0 {
        if (x % 10 == 3) {
            return true;
        }
        x /= 10;
        if (x > 0) {
            return check0(x);
        }
        return false;
    } if (x % 10 == 3) {
            return true;
        } x % 10 == 3 x % 10 x 10 3 {
            return true;
        } return true; true x /= 10 x 10 if (x > 0) {
            return check0(x);
        } x > 0 x 0 {
            return check0(x);
        } return check0(x); check0(x) check0 x return false; false int x x public static void main(String[] args) {
        final String line = readLine();
        System.out.println(calc(line));
    } main {
        final String line = readLine();
        System.out.println(calc(line));
    } final String line = readLine(); line readLine() readLine System.out.println(calc(line)) System.out.println System.out System System.out calc(line) calc line String[] args args private static String readLine() {
        java.util.Scanner s = null;
        try {
            s = new java.util.Scanner(System.in);
            return s.nextLine();
        } finally {
            if (s != null) {
                s.close();
            }
        }
    } readLine {
        java.util.Scanner s = null;
        try {
            s = new java.util.Scanner(System.in);
            return s.nextLine();
        } finally {
            if (s != null) {
                s.close();
            }
        }
    } java.util.Scanner s = null; s null try {
            s = new java.util.Scanner(System.in);
            return s.nextLine();
        } finally {
            if (s != null) {
                s.close();
            }
        } {
            if (s != null) {
                s.close();
            }
        } if (s != null) {
                s.close();
            } s != null s null {
                s.close();
            } s.close() s.close s {
            s = new java.util.Scanner(System.in);
            return s.nextLine();
        } s = new java.util.Scanner(System.in) s new java.util.Scanner(System.in) return s.nextLine(); s.nextLine() s.nextLine s public class Main {

    protected static String calc(String input) {
        final int data = Integer.parseInt(input);

        StringBuilder sb = new StringBuilder();

        for (int i = 1; i <= data; i++) {
            if (check(i)) {
                sb.append(' ');
                sb.append(i);
            }
        }

        return sb.toString();
    }

    static boolean check(int x) {
        if (x % 3 == 0) {
            return true;
        }
        return check0(x);
    }

    static boolean check0(int x) {
        if (x % 10 == 3) {
            return true;
        }
        x /= 10;
        if (x > 0) {
            return check0(x);
        }
        return false;
    }

    public static void main(String[] args) {
        final String line = readLine();
        System.out.println(calc(line));
    }

    private static String readLine() {
        java.util.Scanner s = null;
        try {
            s = new java.util.Scanner(System.in);
            return s.nextLine();
        } finally {
            if (s != null) {
                s.close();
            }
        }
    }
} public class Main {

    protected static String calc(String input) {
        final int data = Integer.parseInt(input);

        StringBuilder sb = new StringBuilder();

        for (int i = 1; i <= data; i++) {
            if (check(i)) {
                sb.append(' ');
                sb.append(i);
            }
        }

        return sb.toString();
    }

    static boolean check(int x) {
        if (x % 3 == 0) {
            return true;
        }
        return check0(x);
    }

    static boolean check0(int x) {
        if (x % 10 == 3) {
            return true;
        }
        x /= 10;
        if (x > 0) {
            return check0(x);
        }
        return false;
    }

    public static void main(String[] args) {
        final String line = readLine();
        System.out.println(calc(line));
    }

    private static String readLine() {
        java.util.Scanner s = null;
        try {
            s = new java.util.Scanner(System.in);
            return s.nextLine();
        } finally {
            if (s != null) {
                s.close();
            }
        }
    }
} Main
public class Main {

    protected static String calc(String input) {
        final int data = Integer.parseInt(input);

        StringBuilder sb = new StringBuilder();

        for (int i = 1; i <= data; i++) {
            if (check(i)) {
                sb.append(' ');
                sb.append(i);
            }
        }

        return sb.toString();
    }

    static boolean check(int x) {
        if (x % 3 == 0) {
            return true;
        }
        return check0(x);
    }

    static boolean check0(int x) {
        if (x % 10 == 3) {
            return true;
        }
        x /= 10;
        if (x > 0) {
            return check0(x);
        }
        return false;
    }

    public static void main(String[] args) {
        final String line = readLine();
        System.out.println(calc(line));
    }

    private static String readLine() {
        java.util.Scanner s = null;
        try {
            s = new java.util.Scanner(System.in);
            return s.nextLine();
        } finally {
            if (s != null) {
                s.close();
            }
        }
    }
}