n = gets.to_i
(1..n).each do |i|
  x = i
  if x % 3 == 0
    print " ", i
  elsif x % 10 == 3
    print " ", i
  else
    until x == 0
      x /= 10
      if x % 10 == 3
        print " ", i
        break
      end
    end
  end
end