n = gets.to_i
i = 1
result = []

def check_num(x)
  return x % 3 == 0
end

def include3(x)
  return x % 10 == 3
end

i..n.times do
  x = i
  if check_num(x)
    result << i
    i += 1
    next
  end
  if include3(x)
    result << i
    i += 1
    next
  end
  x /= 10
  if (x) && include3(x)
    result << i
    i += 1
    next
  end
  x /= 10
  if (x) && include3(x)
    result << i
    i += 1
    next
  end
  x /= 10
  if (x) && include3(x)
    result << i
    i += 1
    next
  end
  x /= 10
  if (x) && include3(x)
    result << i
    i += 1
    next
  end
  i += 1
end

puts ' ' + result.join(' ')

