if __name__ == "__main__":
st,idx = [0]*100010,0
n = int(input())
a = list(map(int,input().split()))
for i in range(n):
x = a[i]
while idx > 0 and st[idx] >= x: idx -= 1
if idx > 0: print(st[idx],end=" ")
else:print(-1,end=" ")
idx +=1
st[idx] = x