N = int(input())
Arr = [int(input()) for i in range(N)]


def funct(i, left_max, right_max):
    n = Arr[i]

    if n==right_max:
        if i ==N-1:
            right_max=0
        else:
            right_max = max(Arr[i+1:])

    print(max(left_max, right_max))

    if i == N-1:
        return

    if n >left_max:
        if i==0:
            left_max=n
        elif i ==1:
            left_max=max(Arr[:1])
        else:
            left_max=n

    return funct(i + 1, left_max, right_max)


funct(0, 0, max(Arr[1:]))
