n = int(input())

a = []
for num in range(n):
  a.append(int(input()))

maxn = max(a)
sortedset = sorted(set(a))
max2n = maxn
if len(sortedset) > 1:
  max2n = sortedset[-2]

for num in a:
  if num != maxn:
    print (maxn)
  else:
    print (max2n)
  

