import std.stdio, std.conv, std.string;

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

  for (int i = 1; i <= n; ++i) {
    if (check(i)) {
      writef(" %d", i);
    }
  }
  writeln("");
}

bool check(int a) {
  if (a % 3 == 0) return true;
  while (a) {
    if (a % 10 == 3) return true;
    a /= 10;
  }

  return false;
}