def call(n)
  i = 1

  (1..n).each do |i| 
    x = i

    if x % 3 == 0
      print " #{i}"
    else
      while x != 0 do
        if x % 10 == 3
          print " #{i}"
          break
        end
        x /= 10
      end
    end
  end
  puts
end

call(gets.to_i)

