import java.util.*;
public class Main{
final static int N = 100010;
static int stk[] = new int[N],tt = -1;
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
for(int i = 0; i < m ; i ++) {
int x = sc.nextInt();
while(tt >= 0 && stk[tt] >= x) tt--;
if(tt > -1) System.out.print(stk[tt] + " ");
else System.out.print("-1 ");
stk[++tt] = x;
}
}
}