if __name__=="__main__":
n=int(input())
q=list(map(int,input().split()))
stack=[]
for value in q:
if stack!=[]:
if value>stack[-1]:
print(stack[-1],end=" ")
stack.append(value)
else:
while stack!=[] and stack[-1]>=value:
del stack[-1]
if stack==[]:
print(-1,end=" ")
else:
print(stack[-1],end=" ")
stack.append(value)
else:
print(-1,end=" ")
stack.append(value)