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



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

  print(m)
  m = b