import math
import sys
import itertools
import queue
from fractions import gcd
import time


def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    N= int(sys.stdin.readline())
    A = list(map(int,sys.stdin.readlines()))
    k=A.pop(0)
    m = max(A)
    A.insert(0,k)
    print(m)
    if k>m:
        m=k
    for i in range(1,len(A)):
        if m == A[i]:
            k=A.pop(i)
            m = max(A)
            A.insert(i,k)
            print(m)
            m=k
        else:
            print(m)