import java.util.*;
public class Main{
public static void main(String... args){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
ArrayDeque<Integer> s = new ArrayDeque<>();
while (n-- > 0){
int cur = in.nextInt();
while (!s.isEmpty() && s.peek() >= cur){
s.pop();
}
if (s.isEmpty()){
System.out.print("-1 ");
} else {
System.out.print(s.peek() + " ");
}
s.push(cur);
}
}
}