#include<bits/stdc++.h>
using namespace std;
#define reg register
#define M 200005
int fir,sec;
int A[M],n;
int main() {
	scanf("%d",&n);
	for(int i=1; i<=n; i++) {
		scanf("%d",A+i);
		if(A[i]>=fir) {
			sec=fir;
			fir=A[i];
		} else if(A[i]>sec)sec=A[i];
	}
	for(int i=1; i<=n; i++)
		printf("%d\n",A[i]==fir?sec:fir);
}

