import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);

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

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

    int x = in.nextInt();
    for (int i = 3; i <= x; i++) {
      if (i % 3 == 0) {
        System.out.print(" " + i);
      }
      else {
        int t = i;
        while (true) {
          if (t % 10 == 3) {
            System.out.print(" " + i);
            break;
          }
          else if (t < 3) {
            break;
          }
          t /= 10;
        }
      }
    }
    System.out.println();
  } main {
    Scanner in = new Scanner(System.in);

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

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

    int x = in.nextInt();
    for (int i = 3; i <= x; i++) {
      if (i % 3 == 0) {
        System.out.print(" " + i);
      }
      else {
        int t = i;
        while (true) {
          if (t % 10 == 3) {
            System.out.print(" " + i);
            break;
          }
          else if (t < 3) {
            break;
          }
          t /= 10;
        }
      }
    }
    System.out.println();
  }
} Main
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);

    int x = in.nextInt();
    for (int i = 3; i <= x; i++) {
      if (i % 3 == 0) {
        System.out.print(" " + i);
      }
      else {
        int t = i;
        while (true) {
          if (t % 10 == 3) {
            System.out.print(" " + i);
            break;
          }
          else if (t < 3) {
            break;
          }
          t /= 10;
        }
      }
    }
    System.out.println();
  }
}