import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner stdin = new Scanner(System.in);
    int n = stdin.nextInt();
    Main.call(n);
  }

  private static void call(int n) {
    for (int i = 1; i <= n; i++) {
      if (i % 3 == 0 || String.valueOf(i).contains("3")) {
        System.out.printf(" %d", i);
      }
    }
    System.out.println("");
  }
} import java.util.Scanner; Scanner java.util public class Main {

  public static void main(String[] args) {
    Scanner stdin = new Scanner(System.in);
    int n = stdin.nextInt();
    Main.call(n);
  }

  private static void call(int n) {
    for (int i = 1; i <= n; i++) {
      if (i % 3 == 0 || String.valueOf(i).contains("3")) {
        System.out.printf(" %d", i);
      }
    }
    System.out.println("");
  }
} Main public static void main(String[] args) {
    Scanner stdin = new Scanner(System.in);
    int n = stdin.nextInt();
    Main.call(n);
  } main {
    Scanner stdin = new Scanner(System.in);
    int n = stdin.nextInt();
    Main.call(n);
  } Scanner stdin = new Scanner(System.in); stdin new Scanner(System.in) int n = stdin.nextInt(); n stdin.nextInt() stdin.nextInt stdin Main.call(n) Main.call Main n String[] args args private static void call(int n) {
    for (int i = 1; i <= n; i++) {
      if (i % 3 == 0 || String.valueOf(i).contains("3")) {
        System.out.printf(" %d", i);
      }
    }
    System.out.println("");
  } call {
    for (int i = 1; i <= n; i++) {
      if (i % 3 == 0 || String.valueOf(i).contains("3")) {
        System.out.printf(" %d", i);
      }
    }
    System.out.println("");
  } for (int i = 1; i <= n; i++) {
      if (i % 3 == 0 || String.valueOf(i).contains("3")) {
        System.out.printf(" %d", i);
      }
    } int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
      if (i % 3 == 0 || String.valueOf(i).contains("3")) {
        System.out.printf(" %d", i);
      }
    } {
      if (i % 3 == 0 || String.valueOf(i).contains("3")) {
        System.out.printf(" %d", i);
      }
    } if (i % 3 == 0 || String.valueOf(i).contains("3")) {
        System.out.printf(" %d", i);
      } i % 3 == 0 || String.valueOf(i).contains("3") i % 3 == 0 i % 3 i 3 0 String.valueOf(i).contains("3") String.valueOf(i).contains String.valueOf(i) String.valueOf String i "3" {
        System.out.printf(" %d", i);
      } System.out.printf(" %d", i) System.out.printf System.out System System.out " %d" i System.out.println("") System.out.println System.out System System.out "" int n n public class Main {

  public static void main(String[] args) {
    Scanner stdin = new Scanner(System.in);
    int n = stdin.nextInt();
    Main.call(n);
  }

  private static void call(int n) {
    for (int i = 1; i <= n; i++) {
      if (i % 3 == 0 || String.valueOf(i).contains("3")) {
        System.out.printf(" %d", i);
      }
    }
    System.out.println("");
  }
} public class Main {

  public static void main(String[] args) {
    Scanner stdin = new Scanner(System.in);
    int n = stdin.nextInt();
    Main.call(n);
  }

  private static void call(int n) {
    for (int i = 1; i <= n; i++) {
      if (i % 3 == 0 || String.valueOf(i).contains("3")) {
        System.out.printf(" %d", i);
      }
    }
    System.out.println("");
  }
} Main
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner stdin = new Scanner(System.in);
    int n = stdin.nextInt();
    Main.call(n);
  }

  private static void call(int n) {
    for (int i = 1; i <= n; i++) {
      if (i % 3 == 0 || String.valueOf(i).contains("3")) {
        System.out.printf(" %d", i);
      }
    }
    System.out.println("");
  }
}