#include <bits/stdc++.h>

using namespace std;

int n,g,l,a[1000005],b,c;

struct sorted{
    int br;
    int p;
};

sorted s[1000005];

bool cmp(sorted a, sorted b){
    return a.br>b.br;
}

void test_cases(){

    for(int i=1; i<=1000000; i++){
        int k = rand()%10;
        printf("%d\n", k);
    }

}

int main(){

    //freopen("tests.txt", "w", stdout);
    //test_cases();
    //return 5;
    scanf("%d", &n);

    if(n==2){
        scanf("%d%d", &b,&c);
        printf("%d %d", c, b);
        return 0;
    }

    for(int i=1; i<=n; i++){
        scanf("%d", &a[i]);
        s[i].br = a[i];
        s[i].p = i;
    }

    sort(s+1,s+n+1,cmp);

    if(s[1].br == a[1]) s[1].br = 0;

    for(int i=1; i<=n; i++){
        if(s[i].br > a[i]){
            a[s[i].p] = a[i];
            a[i] = s[i].br;
            break;
        }
    }

    for(int i=1; i<=n; i++){
        printf("%d ", a[i]);
    }

 return 0;
}