n = int(input())
a = [int(input()) for _ in range(n)]
a_max = max(a)
a_set = set(a)
second = sorted(set(a))[-2] if len(set(a)) >= 2 else a[0]
for i in a:
  if i == a_max:
    print(second)
  else:
    print(a_max)
