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