import java.util.Scanner;

public class Main {
  public static void main(String[] args){
    Scanner r=new Scanner(System.in);
    int t = r.nextInt();
    for (int i = 1;i <= t ;i++ ) {
      int s = i;
      if (s%3==0||s%10==3||s/10==3) {
        System.out.print(" "+i);
      }else{
        while(s!=0){
          s/=10;
          if (s%10==3) {
            System.out.print(" "+i);
            break;
          }
        }
      }
    }
    System.out.println("");
  }
} import java.util.Scanner; Scanner java.util public class Main {
  public static void main(String[] args){
    Scanner r=new Scanner(System.in);
    int t = r.nextInt();
    for (int i = 1;i <= t ;i++ ) {
      int s = i;
      if (s%3==0||s%10==3||s/10==3) {
        System.out.print(" "+i);
      }else{
        while(s!=0){
          s/=10;
          if (s%10==3) {
            System.out.print(" "+i);
            break;
          }
        }
      }
    }
    System.out.println("");
  }
} Main public static void main(String[] args){
    Scanner r=new Scanner(System.in);
    int t = r.nextInt();
    for (int i = 1;i <= t ;i++ ) {
      int s = i;
      if (s%3==0||s%10==3||s/10==3) {
        System.out.print(" "+i);
      }else{
        while(s!=0){
          s/=10;
          if (s%10==3) {
            System.out.print(" "+i);
            break;
          }
        }
      }
    }
    System.out.println("");
  } main {
    Scanner r=new Scanner(System.in);
    int t = r.nextInt();
    for (int i = 1;i <= t ;i++ ) {
      int s = i;
      if (s%3==0||s%10==3||s/10==3) {
        System.out.print(" "+i);
      }else{
        while(s!=0){
          s/=10;
          if (s%10==3) {
            System.out.print(" "+i);
            break;
          }
        }
      }
    }
    System.out.println("");
  } Scanner r=new Scanner(System.in); r new Scanner(System.in) int t = r.nextInt(); t r.nextInt() r.nextInt r for (int i = 1;i <= t ;i++ ) {
      int s = i;
      if (s%3==0||s%10==3||s/10==3) {
        System.out.print(" "+i);
      }else{
        while(s!=0){
          s/=10;
          if (s%10==3) {
            System.out.print(" "+i);
            break;
          }
        }
      }
    } int i = 1; int i = 1; i 1 i <= t i t i++ i++ i {
      int s = i;
      if (s%3==0||s%10==3||s/10==3) {
        System.out.print(" "+i);
      }else{
        while(s!=0){
          s/=10;
          if (s%10==3) {
            System.out.print(" "+i);
            break;
          }
        }
      }
    } {
      int s = i;
      if (s%3==0||s%10==3||s/10==3) {
        System.out.print(" "+i);
      }else{
        while(s!=0){
          s/=10;
          if (s%10==3) {
            System.out.print(" "+i);
            break;
          }
        }
      }
    } int s = i; s i if (s%3==0||s%10==3||s/10==3) {
        System.out.print(" "+i);
      }else{
        while(s!=0){
          s/=10;
          if (s%10==3) {
            System.out.print(" "+i);
            break;
          }
        }
      } s%3==0||s%10==3||s/10==3 s%3==0||s%10==3||s/10==3 s%3==0 s%3 s 3 0 s%10==3 s%10 s 10 3 s/10==3 s/10 s 10 3 {
        System.out.print(" "+i);
      } System.out.print(" "+i) System.out.print System.out System System.out " "+i " " i {
        while(s!=0){
          s/=10;
          if (s%10==3) {
            System.out.print(" "+i);
            break;
          }
        }
      } while(s!=0){
          s/=10;
          if (s%10==3) {
            System.out.print(" "+i);
            break;
          }
        } s!=0 s 0 {
          s/=10;
          if (s%10==3) {
            System.out.print(" "+i);
            break;
          }
        } s/=10 s 10 if (s%10==3) {
            System.out.print(" "+i);
            break;
          } s%10==3 s%10 s 10 3 {
            System.out.print(" "+i);
            break;
          } System.out.print(" "+i) System.out.print System.out System System.out " "+i " " i break; System.out.println("") System.out.println System.out System System.out "" String[] args args public class Main {
  public static void main(String[] args){
    Scanner r=new Scanner(System.in);
    int t = r.nextInt();
    for (int i = 1;i <= t ;i++ ) {
      int s = i;
      if (s%3==0||s%10==3||s/10==3) {
        System.out.print(" "+i);
      }else{
        while(s!=0){
          s/=10;
          if (s%10==3) {
            System.out.print(" "+i);
            break;
          }
        }
      }
    }
    System.out.println("");
  }
} public class Main {
  public static void main(String[] args){
    Scanner r=new Scanner(System.in);
    int t = r.nextInt();
    for (int i = 1;i <= t ;i++ ) {
      int s = i;
      if (s%3==0||s%10==3||s/10==3) {
        System.out.print(" "+i);
      }else{
        while(s!=0){
          s/=10;
          if (s%10==3) {
            System.out.print(" "+i);
            break;
          }
        }
      }
    }
    System.out.println("");
  }
} Main
import java.util.Scanner;

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