def myAnswer(N:int,A:list) -> None:
   MAX = max(A)
   tmp = A[:]
   for i in range(N):
      if(A[i] == MAX):
         tmp.remove(A[i])
         print(max(tmp))
         tmp = A[:]
      else:
         print(MAX)

def modelAnswer():
   tmp=1
def main():
   N = int(input())
   A =[]
   for _ in range(N):
      A.append(int(input()))
   myAnswer(N,A)

if __name__ == '__main__':
   main()