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


def funct(i, left_max, right_max):
    n = Arr[i]
    if left_max>=right_max:
        print(left_max)
    else:
        if n==right_max:
            if i ==N-1:
                right_max=0
            else:
                right_max = max(Arr[i+1:])
    
        print(right_max)
    
    if i == N-1:
        return
    
    left_max=max(n,left_max)
    return funct(i + 1, left_max, right_max)


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