attrs = Array.new
while line = $stdin.gets
    attrs << line.chomp.to_i
end

N = attrs.shift
A = attrs
m = A.max
mc = A.count(m)
for n in 0..(N - 1) do
  if mc > 1 then
    puts m
  else
    if A[n] == m then
      tmp = (A.clone)
      tmp[n] = -1
      puts tmp.max
    else
      puts m
    end
  end
end