import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    StringBuilder sb = new StringBuilder();
    for(int i=1; i<=n; i++){
      if(i%3==0 || i%10==3 ){
        sb.append(" ").append(i);
      }
      else {
        int j = i;
        while(j>=10) {
          j = j/10;
          if(j%10==3){sb.append(" ").append(i);break;} 
        }
      }
    }
    System.out.println(sb);
  }
} import java.util.Scanner; Scanner java.util public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    StringBuilder sb = new StringBuilder();
    for(int i=1; i<=n; i++){
      if(i%3==0 || i%10==3 ){
        sb.append(" ").append(i);
      }
      else {
        int j = i;
        while(j>=10) {
          j = j/10;
          if(j%10==3){sb.append(" ").append(i);break;} 
        }
      }
    }
    System.out.println(sb);
  }
} Main public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    StringBuilder sb = new StringBuilder();
    for(int i=1; i<=n; i++){
      if(i%3==0 || i%10==3 ){
        sb.append(" ").append(i);
      }
      else {
        int j = i;
        while(j>=10) {
          j = j/10;
          if(j%10==3){sb.append(" ").append(i);break;} 
        }
      }
    }
    System.out.println(sb);
  } main {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    StringBuilder sb = new StringBuilder();
    for(int i=1; i<=n; i++){
      if(i%3==0 || i%10==3 ){
        sb.append(" ").append(i);
      }
      else {
        int j = i;
        while(j>=10) {
          j = j/10;
          if(j%10==3){sb.append(" ").append(i);break;} 
        }
      }
    }
    System.out.println(sb);
  } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan StringBuilder sb = new StringBuilder(); sb new StringBuilder() for(int i=1; i<=n; i++){
      if(i%3==0 || i%10==3 ){
        sb.append(" ").append(i);
      }
      else {
        int j = i;
        while(j>=10) {
          j = j/10;
          if(j%10==3){sb.append(" ").append(i);break;} 
        }
      }
    } int i=1; int i=1; i 1 i<=n i n i++ i++ i {
      if(i%3==0 || i%10==3 ){
        sb.append(" ").append(i);
      }
      else {
        int j = i;
        while(j>=10) {
          j = j/10;
          if(j%10==3){sb.append(" ").append(i);break;} 
        }
      }
    } {
      if(i%3==0 || i%10==3 ){
        sb.append(" ").append(i);
      }
      else {
        int j = i;
        while(j>=10) {
          j = j/10;
          if(j%10==3){sb.append(" ").append(i);break;} 
        }
      }
    } if(i%3==0 || i%10==3 ){
        sb.append(" ").append(i);
      }
      else {
        int j = i;
        while(j>=10) {
          j = j/10;
          if(j%10==3){sb.append(" ").append(i);break;} 
        }
      } i%3==0 || i%10==3 i%3==0 i%3 i 3 0 i%10==3 i%10 i 10 3 {
        sb.append(" ").append(i);
      } sb.append(" ").append(i) sb.append(" ").append sb.append(" ") sb.append sb " " i {
        int j = i;
        while(j>=10) {
          j = j/10;
          if(j%10==3){sb.append(" ").append(i);break;} 
        }
      } int j = i; j i while(j>=10) {
          j = j/10;
          if(j%10==3){sb.append(" ").append(i);break;} 
        } j>=10 j 10 {
          j = j/10;
          if(j%10==3){sb.append(" ").append(i);break;} 
        } j = j/10 j j/10 j 10 if(j%10==3){sb.append(" ").append(i);break;} j%10==3 j%10 j 10 3 {sb.append(" ").append(i);break;} sb.append(" ").append(i) sb.append(" ").append sb.append(" ") sb.append sb " " i break; System.out.println(sb) System.out.println System.out System System.out sb String[] args args public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    StringBuilder sb = new StringBuilder();
    for(int i=1; i<=n; i++){
      if(i%3==0 || i%10==3 ){
        sb.append(" ").append(i);
      }
      else {
        int j = i;
        while(j>=10) {
          j = j/10;
          if(j%10==3){sb.append(" ").append(i);break;} 
        }
      }
    }
    System.out.println(sb);
  }
} public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    StringBuilder sb = new StringBuilder();
    for(int i=1; i<=n; i++){
      if(i%3==0 || i%10==3 ){
        sb.append(" ").append(i);
      }
      else {
        int j = i;
        while(j>=10) {
          j = j/10;
          if(j%10==3){sb.append(" ").append(i);break;} 
        }
      }
    }
    System.out.println(sb);
  }
} Main
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    StringBuilder sb = new StringBuilder();
    for(int i=1; i<=n; i++){
      if(i%3==0 || i%10==3 ){
        sb.append(" ").append(i);
      }
      else {
        int j = i;
        while(j>=10) {
          j = j/10;
          if(j%10==3){sb.append(" ").append(i);break;} 
        }
      }
    }
    System.out.println(sb);
  }
}