# coding: utf-8
# Your code here!
import sys
from collections import deque

def input():
    return sys.stdin.readline().rstrip()

N = int(input())
que = deque([int(input()) for i in range(N)])
tmp = 0
max_num = max(set(que))

for i in range(N):
    tmp = que.popleft()
    if tmp != max_num:
        print(max_num)
    else:
        print(max(set(que)))
    que.append(tmp)