#include <iostream>

using namespace std;

int main(void){
	
	int n;
	cin >> n;
	
	int a[n];
	for(int i = 0; i < n; ++i){
		cin >> a[i];
	}
	
	int max = 0, smax = -1;
	for(int i = 1; i < n; ++i){
		if(a[max] < a[i]){
			smax = max;
			max = i;
		}
	}
	if(max == 0 && smax == -1) smax = 1
	if(max + 1 < n){
		for(int i = max+1; i < n; ++i){
			if(a[smax] < a[i]){
				smax = i;
			}
		}
	}
	
	for(int i = 0; i < n; ++i){
		if(i == max){
			cout << a[smax] << endl;
		}else{
			cout << a[max] << endl;
		}
	}
	
	return 0;
}