import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.container;
import std.bigint;
import std.math;

void main()
{
	auto n = readln.chomp.to!int;
  foreach (i; 1..n+1) {
    auto x = i;
    if (x % 3 == 0) {
      write(" ", i);
      continue;
    }
    while (x) {
      if (x % 10 == 3) {
        write(" ", i);
        break;
      }
      x /= 10;
    }
  }
  writeln("");
}