N = int(input())
A = list()
for i in range(N):
  A.append(int(input()))
ma = max(A)
am = sorted(A,reverse = True)
for i in range(N):
  if ma != A[i]:
    print(ma)
  else:
    print(am[1])
print(am)
  