import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random, core.bitop;
import std.string, std.conv, std.stdio, std.typecons;

void main()
{
  auto n = readln.chomp.to!int;

  bool include3(int x) {
    for (; x > 0; x /= 10)
      if (x % 10 == 3) return true;

    return false;
  }

  foreach (i; 1..n + 1)
    if (i % 3 == 0 || include3(i)) write(" ", i);

  writeln;
}