import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt(), nabeatsu;

        for (int i=3; i<=n; i++) {
            nabeatsu = i;
            if (nabeatsu % 3 == 0) {
                System.out.print(" " + i);
                continue;
            }
            while (nabeatsu != 0) {
                if (nabeatsu % 10 == 3) {
                    System.out.print(" " + i);
                    break;
                }
                nabeatsu /= 10;
            }
        }
        System.out.println();
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt(), nabeatsu;

        for (int i=3; i<=n; i++) {
            nabeatsu = i;
            if (nabeatsu % 3 == 0) {
                System.out.print(" " + i);
                continue;
            }
            while (nabeatsu != 0) {
                if (nabeatsu % 10 == 3) {
                    System.out.print(" " + i);
                    break;
                }
                nabeatsu /= 10;
            }
        }
        System.out.println();
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt(), nabeatsu;

        for (int i=3; i<=n; i++) {
            nabeatsu = i;
            if (nabeatsu % 3 == 0) {
                System.out.print(" " + i);
                continue;
            }
            while (nabeatsu != 0) {
                if (nabeatsu % 10 == 3) {
                    System.out.print(" " + i);
                    break;
                }
                nabeatsu /= 10;
            }
        }
        System.out.println();
    } main {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt(), nabeatsu;

        for (int i=3; i<=n; i++) {
            nabeatsu = i;
            if (nabeatsu % 3 == 0) {
                System.out.print(" " + i);
                continue;
            }
            while (nabeatsu != 0) {
                if (nabeatsu % 10 == 3) {
                    System.out.print(" " + i);
                    break;
                }
                nabeatsu /= 10;
            }
        }
        System.out.println();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt() n sc.nextInt() sc.nextInt sc nabeatsu; nabeatsu for (int i=3; i<=n; i++) {
            nabeatsu = i;
            if (nabeatsu % 3 == 0) {
                System.out.print(" " + i);
                continue;
            }
            while (nabeatsu != 0) {
                if (nabeatsu % 10 == 3) {
                    System.out.print(" " + i);
                    break;
                }
                nabeatsu /= 10;
            }
        } int i=3; int i=3; i 3 i<=n i n i++ i++ i {
            nabeatsu = i;
            if (nabeatsu % 3 == 0) {
                System.out.print(" " + i);
                continue;
            }
            while (nabeatsu != 0) {
                if (nabeatsu % 10 == 3) {
                    System.out.print(" " + i);
                    break;
                }
                nabeatsu /= 10;
            }
        } {
            nabeatsu = i;
            if (nabeatsu % 3 == 0) {
                System.out.print(" " + i);
                continue;
            }
            while (nabeatsu != 0) {
                if (nabeatsu % 10 == 3) {
                    System.out.print(" " + i);
                    break;
                }
                nabeatsu /= 10;
            }
        } nabeatsu = i nabeatsu i if (nabeatsu % 3 == 0) {
                System.out.print(" " + i);
                continue;
            } nabeatsu % 3 == 0 nabeatsu % 3 nabeatsu 3 0 {
                System.out.print(" " + i);
                continue;
            } System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i continue; while (nabeatsu != 0) {
                if (nabeatsu % 10 == 3) {
                    System.out.print(" " + i);
                    break;
                }
                nabeatsu /= 10;
            } nabeatsu != 0 nabeatsu 0 {
                if (nabeatsu % 10 == 3) {
                    System.out.print(" " + i);
                    break;
                }
                nabeatsu /= 10;
            } if (nabeatsu % 10 == 3) {
                    System.out.print(" " + i);
                    break;
                } nabeatsu % 10 == 3 nabeatsu % 10 nabeatsu 10 3 {
                    System.out.print(" " + i);
                    break;
                } System.out.print(" " + i) System.out.print System.out System System.out " " + i " " i break; nabeatsu /= 10 nabeatsu 10 System.out.println() System.out.println System.out System System.out String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt(), nabeatsu;

        for (int i=3; i<=n; i++) {
            nabeatsu = i;
            if (nabeatsu % 3 == 0) {
                System.out.print(" " + i);
                continue;
            }
            while (nabeatsu != 0) {
                if (nabeatsu % 10 == 3) {
                    System.out.print(" " + i);
                    break;
                }
                nabeatsu /= 10;
            }
        }
        System.out.println();
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt(), nabeatsu;

        for (int i=3; i<=n; i++) {
            nabeatsu = i;
            if (nabeatsu % 3 == 0) {
                System.out.print(" " + i);
                continue;
            }
            while (nabeatsu != 0) {
                if (nabeatsu % 10 == 3) {
                    System.out.print(" " + i);
                    break;
                }
                nabeatsu /= 10;
            }
        }
        System.out.println();
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt(), nabeatsu;

        for (int i=3; i<=n; i++) {
            nabeatsu = i;
            if (nabeatsu % 3 == 0) {
                System.out.print(" " + i);
                continue;
            }
            while (nabeatsu != 0) {
                if (nabeatsu % 10 == 3) {
                    System.out.print(" " + i);
                    break;
                }
                nabeatsu /= 10;
            }
        }
        System.out.println();
    }
}