import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(reader.readLine());
    int i = 1;
    CHECK_NUM:
    while (true) {
      int x = i;
      if (x % 3 == 0) {
        System.out.print(" " + i);
        if (++i <= n)
          continue;
        else
          break;
      }
      INCLUDE3:
      while (true) {
        if (x % 10 == 3) {
          System.out.print(" " + i);
          if (++i <= n)
            continue CHECK_NUM;
          else
            break CHECK_NUM;
        }
        x /= 10;
        if (x != 0); else {
          if (++i <= n)
            continue CHECK_NUM;
          else
            break CHECK_NUM;
        }
      }
    }
    System.out.println();
  }

} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

  public static void main(String[] args) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(reader.readLine());
    int i = 1;
    CHECK_NUM:
    while (true) {
      int x = i;
      if (x % 3 == 0) {
        System.out.print(" " + i);
        if (++i <= n)
          continue;
        else
          break;
      }
      INCLUDE3:
      while (true) {
        if (x % 10 == 3) {
          System.out.print(" " + i);
          if (++i <= n)
            continue CHECK_NUM;
          else
            break CHECK_NUM;
        }
        x /= 10;
        if (x != 0); else {
          if (++i <= n)
            continue CHECK_NUM;
          else
            break CHECK_NUM;
        }
      }
    }
    System.out.println();
  }

} Main public static void main(String[] args) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(reader.readLine());
    int i = 1;
    CHECK_NUM:
    while (true) {
      int x = i;
      if (x % 3 == 0) {
        System.out.print(" " + i);
        if (++i <= n)
          continue;
        else
          break;
      }
      INCLUDE3:
      while (true) {
        if (x % 10 == 3) {
          System.out.print(" " + i);
          if (++i <= n)
            continue CHECK_NUM;
          else
            break CHECK_NUM;
        }
        x /= 10;
        if (x != 0); else {
          if (++i <= n)
            continue CHECK_NUM;
          else
            break CHECK_NUM;
        }
      }
    }
    System.out.println();
  } main {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(reader.readLine());
    int i = 1;
    CHECK_NUM:
    while (true) {
      int x = i;
      if (x % 3 == 0) {
        System.out.print(" " + i);
        if (++i <= n)
          continue;
        else
          break;
      }
      INCLUDE3:
      while (true) {
        if (x % 10 == 3) {
          System.out.print(" " + i);
          if (++i <= n)
            continue CHECK_NUM;
          else
            break CHECK_NUM;
        }
        x /= 10;
        if (x != 0); else {
          if (++i <= n)
            continue CHECK_NUM;
          else
            break CHECK_NUM;
        }
      }
    }
    System.out.println();
  } BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); reader new BufferedReader(new InputStreamReader(System.in)) int n = Integer.parseInt(reader.readLine()); n Integer.parseInt(reader.readLine()) Integer.parseInt Integer reader.readLine() reader.readLine reader int i = 1; i 1 System.out.println() System.out.println System.out System System.out String[] args args public class Main {

  public static void main(String[] args) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(reader.readLine());
    int i = 1;
    CHECK_NUM:
    while (true) {
      int x = i;
      if (x % 3 == 0) {
        System.out.print(" " + i);
        if (++i <= n)
          continue;
        else
          break;
      }
      INCLUDE3:
      while (true) {
        if (x % 10 == 3) {
          System.out.print(" " + i);
          if (++i <= n)
            continue CHECK_NUM;
          else
            break CHECK_NUM;
        }
        x /= 10;
        if (x != 0); else {
          if (++i <= n)
            continue CHECK_NUM;
          else
            break CHECK_NUM;
        }
      }
    }
    System.out.println();
  }

} public class Main {

  public static void main(String[] args) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(reader.readLine());
    int i = 1;
    CHECK_NUM:
    while (true) {
      int x = i;
      if (x % 3 == 0) {
        System.out.print(" " + i);
        if (++i <= n)
          continue;
        else
          break;
      }
      INCLUDE3:
      while (true) {
        if (x % 10 == 3) {
          System.out.print(" " + i);
          if (++i <= n)
            continue CHECK_NUM;
          else
            break CHECK_NUM;
        }
        x /= 10;
        if (x != 0); else {
          if (++i <= n)
            continue CHECK_NUM;
          else
            break CHECK_NUM;
        }
      }
    }
    System.out.println();
  }

} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(reader.readLine());
    int i = 1;
    CHECK_NUM:
    while (true) {
      int x = i;
      if (x % 3 == 0) {
        System.out.print(" " + i);
        if (++i <= n)
          continue;
        else
          break;
      }
      INCLUDE3:
      while (true) {
        if (x % 10 == 3) {
          System.out.print(" " + i);
          if (++i <= n)
            continue CHECK_NUM;
          else
            break CHECK_NUM;
        }
        x /= 10;
        if (x != 0); else {
          if (++i <= n)
            continue CHECK_NUM;
          else
            break CHECK_NUM;
        }
      }
    }
    System.out.println();
  }

}