public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n;
    int i, x;

    n = sc.nextInt();

    for(i = 0;i < n;i++){
      x = i + 1;
      if(x % 3 == 0){
        System.out.print(" " + x);
      }else{
        for(;;){
          if(x % 10 == 3){
            System.out.print(" " + (i + 1));
            break;
          }else{
            x /= 10;
            if(x == 0)break;
          }
        }
      }
    }
    System.out.println();

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
} public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n;
    int i, x;

    n = sc.nextInt();

    for(i = 0;i < n;i++){
      x = i + 1;
      if(x % 3 == 0){
        System.out.print(" " + x);
      }else{
        for(;;){
          if(x % 10 == 3){
            System.out.print(" " + (i + 1));
            break;
          }else{
            x /= 10;
            if(x == 0)break;
          }
        }
      }
    }
    System.out.println();

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
} Main public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n;
    int i, x;

    n = sc.nextInt();

    for(i = 0;i < n;i++){
      x = i + 1;
      if(x % 3 == 0){
        System.out.print(" " + x);
      }else{
        for(;;){
          if(x % 10 == 3){
            System.out.print(" " + (i + 1));
            break;
          }else{
            x /= 10;
            if(x == 0)break;
          }
        }
      }
    }
    System.out.println();

    sc.close();
  } run {
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n;
    int i, x;

    n = sc.nextInt();

    for(i = 0;i < n;i++){
      x = i + 1;
      if(x % 3 == 0){
        System.out.print(" " + x);
      }else{
        for(;;){
          if(x % 10 == 3){
            System.out.print(" " + (i + 1));
            break;
          }else{
            x /= 10;
            if(x == 0)break;
          }
        }
      }
    }
    System.out.println();

    sc.close();
  } java.util.Scanner sc = new java.util.Scanner(in); sc new java.util.Scanner(in) int n; n int i i x; x n = sc.nextInt() n sc.nextInt() sc.nextInt sc for(i = 0;i < n;i++){
      x = i + 1;
      if(x % 3 == 0){
        System.out.print(" " + x);
      }else{
        for(;;){
          if(x % 10 == 3){
            System.out.print(" " + (i + 1));
            break;
          }else{
            x /= 10;
            if(x == 0)break;
          }
        }
      }
    } i = 0; i = 0 i 0 i < n i n i++ i++ i {
      x = i + 1;
      if(x % 3 == 0){
        System.out.print(" " + x);
      }else{
        for(;;){
          if(x % 10 == 3){
            System.out.print(" " + (i + 1));
            break;
          }else{
            x /= 10;
            if(x == 0)break;
          }
        }
      }
    } {
      x = i + 1;
      if(x % 3 == 0){
        System.out.print(" " + x);
      }else{
        for(;;){
          if(x % 10 == 3){
            System.out.print(" " + (i + 1));
            break;
          }else{
            x /= 10;
            if(x == 0)break;
          }
        }
      }
    } x = i + 1 x i + 1 i 1 if(x % 3 == 0){
        System.out.print(" " + x);
      }else{
        for(;;){
          if(x % 10 == 3){
            System.out.print(" " + (i + 1));
            break;
          }else{
            x /= 10;
            if(x == 0)break;
          }
        }
      } x % 3 == 0 x % 3 x 3 0 {
        System.out.print(" " + x);
      } System.out.print(" " + x) System.out.print System.out System System.out " " + x " " x {
        for(;;){
          if(x % 10 == 3){
            System.out.print(" " + (i + 1));
            break;
          }else{
            x /= 10;
            if(x == 0)break;
          }
        }
      } for(;;){
          if(x % 10 == 3){
            System.out.print(" " + (i + 1));
            break;
          }else{
            x /= 10;
            if(x == 0)break;
          }
        } ; {
          if(x % 10 == 3){
            System.out.print(" " + (i + 1));
            break;
          }else{
            x /= 10;
            if(x == 0)break;
          }
        } {
          if(x % 10 == 3){
            System.out.print(" " + (i + 1));
            break;
          }else{
            x /= 10;
            if(x == 0)break;
          }
        } if(x % 10 == 3){
            System.out.print(" " + (i + 1));
            break;
          }else{
            x /= 10;
            if(x == 0)break;
          } x % 10 == 3 x % 10 x 10 3 {
            System.out.print(" " + (i + 1));
            break;
          } System.out.print(" " + (i + 1)) System.out.print System.out System System.out " " + (i + 1) " " (i + 1) i 1 break; {
            x /= 10;
            if(x == 0)break;
          } x /= 10 x 10 if(x == 0)break; x == 0 x 0 break; System.out.println() System.out.println System.out System System.out sc.close() sc.close sc java.io.InputStream in in java.io.PrintStream out out public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  } main {
    (new Main()).run(System.in, System.out);
  } (new Main()).run(System.in, System.out) (new Main()).run (new Main()) System.in System System.in System.out System System.out String[] args args public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n;
    int i, x;

    n = sc.nextInt();

    for(i = 0;i < n;i++){
      x = i + 1;
      if(x % 3 == 0){
        System.out.print(" " + x);
      }else{
        for(;;){
          if(x % 10 == 3){
            System.out.print(" " + (i + 1));
            break;
          }else{
            x /= 10;
            if(x == 0)break;
          }
        }
      }
    }
    System.out.println();

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
} public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n;
    int i, x;

    n = sc.nextInt();

    for(i = 0;i < n;i++){
      x = i + 1;
      if(x % 3 == 0){
        System.out.print(" " + x);
      }else{
        for(;;){
          if(x % 10 == 3){
            System.out.print(" " + (i + 1));
            break;
          }else{
            x /= 10;
            if(x == 0)break;
          }
        }
      }
    }
    System.out.println();

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
} Main
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n;
    int i, x;

    n = sc.nextInt();

    for(i = 0;i < n;i++){
      x = i + 1;
      if(x % 3 == 0){
        System.out.print(" " + x);
      }else{
        for(;;){
          if(x % 10 == 3){
            System.out.print(" " + (i + 1));
            break;
          }else{
            x /= 10;
            if(x == 0)break;
          }
        }
      }
    }
    System.out.println();

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}