def call(n)
  i = 1
  ans = []
  while i <= n do
    # CHECK_NUM
    x = i
    if x % 3 == 0
      ans << i
    else
      # INCLUDE 3
      while x != 0 do
        if x % 10 == 3
          ans << i
          break
        else
          x /= 10
        end
      end
    end
    i += 1
  end
  ans
end

puts call(gets.to_i).join(" ")
