#include <cstdio>
using namespace std;
int a[1000000]={0},s[1000000]={0},pos[1000000]={0};
int main(void)
{
freopen("smallblack.in","r",stdin);
freopen("smallblack.out","w",stdout);
int i,j,n;
scanf("%d\n",&n);
for (i=0;i<n;i++)
{
scanf("%d ",&a[i]);
for (j=i-1;j>=0;j=pos[j])
if (a[j]<a[i])
break;
if (j>=0)
s[i]=a[j];
pos[i]=j;
}
for (i=0;i<n-1;i++)
printf("%d ",s[i]);
printf("%d\n",s[i]);
fclose(stdin);
fclose(stdout);
return(0);
}