def is_puts?(num)
  return true if num % 3 == 0
  while num > 0
    num /= 10
    return true if num == 3
  end
  return false
end
 
n = gets.chomp.to_i
str = ''
(1..n).each do |i|
  if is_puts?(i)
    str << " #{i}"
  end
end
puts str