import sys
input = sys.stdin.readline
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
a_max = max(a)
b = a
b.remove(max(b))
b_max = max(b)
for j in range(n):
  if a[j] == a_max:
    print(b_max)
  else:
    print(a_max)