N = int(input())
A = [input() for _ in range(N)]



m = max(A)
sec = 0
for k in range(0, len(A)):
  if(int(A[k]) == int(m)):
    for j in range(0, len(A)):
      if(sec < int(A[j]) and j != k):
        m = A[j]

  print(m)