def call( n )
  s = ""
  
  (1..n).each do |i|
    if i % 3 == 0
      s << " #{i}"
      next
    end
      
    x = i
    while x > 0
      if x % 10 == 3
        s << " #{i}"
        break
      end
      x /= 10
    end
  end

  s << "\n"

  return s
end

n = gets.to_i
print call n