n = gets.chomp.to_i
res = ['']
(1..n).each do |i|
  x = i
  if x % 3 == 0
    res << i
  else
    while x > 0
      if x % 10 == 3
        res << i
        break
      end
      x /= 10
    end
  end
end
print res.join(' '), "\n"