n = $stdin.readline.to_i

(1..n).each do |i|
  if i % 3 == 0
    print " "
    print i
    next
  end

  x = i
  while true
    if x % 10 == 3
      print " "
      print i
      break
    end

    x /= 10
    if x == 0
      break
    end
  end
end

puts

