    for i in 1..n do
        if i%3==0
            print " ",i
        else
            x = i
            while x > 0 do
                if x%10==3
                    print " ",i
                    break
                end
                x /= 10
            end
        end
    end
    puts
end

n = gets.to_i
call(n)