n = gets.to_i
s = ""
(1...(n + 1)).each do |i|
  x = i
  if (x % 3 == 0)
    s += " #{i}"
  else
    loop do
      if ( x % 10 == 3)
	s += " #{i}"
	break
      else
	x /= 10
	break if x
      end
    end
  end
end
puts s