#include <bits/stdc++.h>
#define pb push_back

using namespace std;

const int N = 1e6;
int arr[N] = {};

int main()
{
    int n, maxDig = 0, maxDigID = 0;
    cin >> n;
    if(n==2)
    {
        int a, b;
        cin >> a >> b;
        return cout << b << " " << a, 0;
    }
    for(int i=0; i<n; i++)
    {
        cin >> arr[i];
        if(i and arr[i]>=maxDig)
        {
            maxDig = max(maxDig, arr[i]);
            maxDigID = i;
        }
    }
    if(arr[0] < maxDig)
    {
        swap(arr[0],arr[maxDigID]);
        for(int i=0; i<n; i++) cout << arr[i] << " ";
        return cout << endl, 0;
    }
    else
    {
        int ID = 1;
        while(ID < n-1 and arr[ID] >= maxDig)
        {
            ID++;
        }
        swap(arr[ID], arr[maxDigID]);
        for(int i=0; i<n; i++) cout << arr[i] << " ";
        return cout << endl, 0;
    }
}