def call(n)
  count = ''
  1.upto(n) do |i|
    x = i
    if x % 3 == 0
      count << " " + i.to_s
      next
    elsif
        while x.to_i != 0 do
          if x % 10 == 3
            count << " " + i.to_s
            break
          end
           x = x / 10
        end
    end
  end
  count
end

number = gets.to_i
puts call(number)
