n = int(input())
a = [int(input()) for _ in range(n)] + [0]
ans = [max(a[1:])]

for i in range(1, n):
    if a[i] in a[:i] or a[i] in a[i+1:]:
        ans.append(ans[i-1])
    else:
        max_l = max(a[:i])
        max_r = max(a[i+1:])
        ans.append(max(max_l, max_r))

print(*ans, sep='\n')