n = int(input())
a = [[i, int(input())] for i in range(n)]
a.sort(reverse=True, key=lambda x:x[1])
first, second = a[0][1], a[1][1]
a.sort(reverse=True, key=lambda x:x[0])
for i in range(n):
  print(first if a[i][1] != first else second)