#include <iostream>
#include <vector>
using namespace std;

int main() {
	unsigned int n;
	int min, max;
	
	
	cin >> n;
	
	vector <int> ar(n);
	
	for (int i = 0; i < n; i++) {
		int temp;
		cin >> temp;
		
		if (i == 0) {
			min = temp; max = temp;
		} else {
			if (temp < min) {
				min = temp;
			}
			
			if (temp > max) {
				max = temp;
			}
		}
		
		ar[i] = temp;
	}
	
	for (int i = 0; i < n; i++) {
		if (ar[i] == max) {cout << min << " "; continue;}
		cout << ar[i] << " ";
	}

	return 0;
}