function main()
  
  N = parse(Int,readline())
  A = zeros(Int,N)
  
  for i in 1:N
    A[i] = parse(Int,readline())
  end
  
  max = maximum(A)
  second = minimum(A)
  
  for i in 1:N

    if maximum([second,A[i]]) < max
      second = maximum([second,A[i]])
    end
    
  end
  
  for i in 1:N
    
    if A[i] == max
      println(second)
    else
      println(max)
    end
    
  end
  
end

main()