#include<bits/stdc++.h>
using namespace std;

int a[200005];

int main()
{
	int n;
	scanf("%d",&n);
	int mx=0,sx=0;
	for(int i=1;i<=n;++i) {
		scanf("%d",&a[i]);
		if(mx<a[i]) sx=mx,mx=a[i];
		else if(sx<a[i]) sx=a[i];
	}
	for(int i=1;i<=n;++i) {
		if(a[i]==mx) printf("%d\n",sx);
		else printf("%d\n",mx);
	}
}