import java.util.Scanner;

public class Main {
  private static int input_num, x;
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    input_num = stdIn.nextInt();
    for (int i = 1;i <= input_num; i++) {
      x = i;
      if (x % 3 == 0) {
        System.out.print(" "+ x);
        continue;
      }
      while (x > 0) {
        if (x % 10 == 3) {
          System.out.print(" "+ i);
          break;
        }
        x /= 10;
      }
    }
    System.out.println("");
  }
} import java.util.Scanner; Scanner java.util public class Main {
  private static int input_num, x;
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    input_num = stdIn.nextInt();
    for (int i = 1;i <= input_num; i++) {
      x = i;
      if (x % 3 == 0) {
        System.out.print(" "+ x);
        continue;
      }
      while (x > 0) {
        if (x % 10 == 3) {
          System.out.print(" "+ i);
          break;
        }
        x /= 10;
      }
    }
    System.out.println("");
  }
} Main private static int input_num input_num x; x public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    input_num = stdIn.nextInt();
    for (int i = 1;i <= input_num; i++) {
      x = i;
      if (x % 3 == 0) {
        System.out.print(" "+ x);
        continue;
      }
      while (x > 0) {
        if (x % 10 == 3) {
          System.out.print(" "+ i);
          break;
        }
        x /= 10;
      }
    }
    System.out.println("");
  } main {
    Scanner stdIn = new Scanner(System.in);
    input_num = stdIn.nextInt();
    for (int i = 1;i <= input_num; i++) {
      x = i;
      if (x % 3 == 0) {
        System.out.print(" "+ x);
        continue;
      }
      while (x > 0) {
        if (x % 10 == 3) {
          System.out.print(" "+ i);
          break;
        }
        x /= 10;
      }
    }
    System.out.println("");
  } Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) input_num = stdIn.nextInt() input_num stdIn.nextInt() stdIn.nextInt stdIn for (int i = 1;i <= input_num; i++) {
      x = i;
      if (x % 3 == 0) {
        System.out.print(" "+ x);
        continue;
      }
      while (x > 0) {
        if (x % 10 == 3) {
          System.out.print(" "+ i);
          break;
        }
        x /= 10;
      }
    } int i = 1; int i = 1; i 1 i <= input_num i input_num i++ i++ i {
      x = i;
      if (x % 3 == 0) {
        System.out.print(" "+ x);
        continue;
      }
      while (x > 0) {
        if (x % 10 == 3) {
          System.out.print(" "+ i);
          break;
        }
        x /= 10;
      }
    } {
      x = i;
      if (x % 3 == 0) {
        System.out.print(" "+ x);
        continue;
      }
      while (x > 0) {
        if (x % 10 == 3) {
          System.out.print(" "+ i);
          break;
        }
        x /= 10;
      }
    } x = i x i if (x % 3 == 0) {
        System.out.print(" "+ x);
        continue;
      } x % 3 == 0 x % 3 x 3 0 {
        System.out.print(" "+ x);
        continue;
      } System.out.print(" "+ x) System.out.print System.out System System.out " "+ x " " x continue; while (x > 0) {
        if (x % 10 == 3) {
          System.out.print(" "+ i);
          break;
        }
        x /= 10;
      } x > 0 x 0 {
        if (x % 10 == 3) {
          System.out.print(" "+ i);
          break;
        }
        x /= 10;
      } if (x % 10 == 3) {
          System.out.print(" "+ i);
          break;
        } x % 10 == 3 x % 10 x 10 3 {
          System.out.print(" "+ i);
          break;
        } System.out.print(" "+ i) System.out.print System.out System System.out " "+ i " " i break; x /= 10 x 10 System.out.println("") System.out.println System.out System System.out "" String[] args args public class Main {
  private static int input_num, x;
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    input_num = stdIn.nextInt();
    for (int i = 1;i <= input_num; i++) {
      x = i;
      if (x % 3 == 0) {
        System.out.print(" "+ x);
        continue;
      }
      while (x > 0) {
        if (x % 10 == 3) {
          System.out.print(" "+ i);
          break;
        }
        x /= 10;
      }
    }
    System.out.println("");
  }
} public class Main {
  private static int input_num, x;
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    input_num = stdIn.nextInt();
    for (int i = 1;i <= input_num; i++) {
      x = i;
      if (x % 3 == 0) {
        System.out.print(" "+ x);
        continue;
      }
      while (x > 0) {
        if (x % 10 == 3) {
          System.out.print(" "+ i);
          break;
        }
        x /= 10;
      }
    }
    System.out.println("");
  }
} Main
import java.util.Scanner;

public class Main {
  private static int input_num, x;
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    input_num = stdIn.nextInt();
    for (int i = 1;i <= input_num; i++) {
      x = i;
      if (x % 3 == 0) {
        System.out.print(" "+ x);
        continue;
      }
      while (x > 0) {
        if (x % 10 == 3) {
          System.out.print(" "+ i);
          break;
        }
        x /= 10;
      }
    }
    System.out.println("");
  }
}