import std.stdio;
import std.conv;
import std.string;
import std.algorithm;

void call(int n) {
    foreach(i;1..n+1) {
        if(i%3==0)
            writef(" %d",i);
        else {
            int x = i;
            while(x>0)
            {
                if( x%10==3 )
                {
                    writef(" %d",i);
                    break;
                }
                x = x/10;
            }
        }
    }
    writeln();
}

void main()
{
  auto n = readln;
  call(n.strip.to!int);
}