n = gets.to_i

for i in 1..n
    
    if i % 3 == 0
        print " #{i}"
    else
        x = i
        for j in 1..4
            
            if x  == 0
                break
            elsif x % 10 == 3
                print " #{i}"
                break
            end
            
            x /= 10
        end
    end
end

puts ""
