n = gets.to_i

i = 1
loop do
  x = i
  if (x % 3).zero?
    print " #{i}"
  else
    catch(:jump) do
      if x % 10 == 3
        print " #{i}"
      else
        x /= 10
        throw(:jump) unless x.zero?
      end
    end
  end
  i += 1
  break if i > n
end
puts
