#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
	long unsigned int N;
	long unsigned int i,j;
	int temp,temp2;
	std::vector <int> books,sorted_books;

	std::cin >> N;

	for (i = 0; i < N; i++) {
		std::cin >> temp;
		books.push_back(temp);
		sorted_books.push_back(temp);
	}


	if (N == 2) {
		std::cout << books[1] << " " << books[0];

		return 0;
	}

	else {
		std::sort(sorted_books.begin(), sorted_books.end());
		for (i = 0; i < N; i++) {
			if (books[i] != sorted_books[N - 1 - i]) {
				temp = books[i];
				temp2 = sorted_books[N - 1 - i];
				break;
			}
			if (i == N - 1) {
				temp = books[i];
				temp2 = books[i - 1];
			}
		}
	}

	for (i = 0; i < N; i++) {
		if (books[i] == temp) {
			std::cout << temp2 << " ";
		}
		else {
			if (books[i] == temp2) {
				std::cout << temp << " ";
			}
			else {
				std::cout << books[i] << " ";
			}
		}
	}
    
}