n = int(input())
s = []
for i in range(n):
    s.append(int(input()))
    
p = max(s)
for i in s:
    if i != p:
        print(p)
    else:
        s.remove(p)
        print(max(s))
        s.insert(0,p)
