N = gets.to_i
arr = N.times.map{ gets.to_i }

sort_arr = arr.sort
max_num = sort_arr[arr.count - 1]
next_max_num = sort_arr[arr.count - 2]

arr.each do |i|
  if i == max_num
    puts next_max_num
  else
    puts max_num
  end
end