n = gets.strip.to_i
a = n.times.map{ gets.strip.to_i }

max = 1
nxt = 0

(0..n-1).each do |i|
  max = a[i] if a[i] > max
  nxt = max if a[i] == max
  if a[i] > nxt && a[i] < max
    nxt = a[i]
  end
end

(0..n-1).each do |i|
  if a[i] == max
    puts nxt
  else
    puts max
  end
end