N = int(input())
s = [int(input()) for i in range(N)]
temp=s.copy()
s_max=temp.remove(max(temp))
s_max2=temp.remove(max(temp))

for i in range(N):
  if s[i]<s_max:
    print(s_max)
  else:
	print(s_max2)
