from collections import Counter
n = int(input())
a = [int(input()) for i in range(n)]

cnt = Counter(a)
for i in range(n):
  temp = cnt.copy()
  temp[a[i]] -= 1
  if temp[a[i]] == 0:
    del temp[a[i]]

  print(max(temp.keys()))


