#include <stdio.h>
#include <stdlib.h>

int main()
{
    // Input
    int N;
    scanf("%d", &N);
    int numbers[N];
    int largest = -1;
    int tracker = 0, replacer = 0;

    for (int i =0 ; i < N; ++i) {
        scanf("%d", &numbers[i]);
    }

    // Work
    for (int i = 0; i < N-1; ++i) {

        for (int j = N-1; j > i; --j)
        {
            if (numbers[i] < numbers[j] && largest < numbers[j]) {
                //printf("Crucial IF statement with iteration %i and number %d\n", i, numbers[j]);
                largest = numbers[j];
                tracker = j;
                replacer = i;
                }
        }

    }

    // Result
    if (largest == -1) {
        int tmp = numbers[N-1];
        numbers[N-1] = numbers[N-2];
        numbers[N-2] = tmp;

        for (int i = 0; i < N; i++) {
            printf("%d", numbers[i]);
        }
    }else {
        int temp = numbers[tracker];
        numbers[tracker] = numbers[replacer];
        numbers[replacer] = temp;

        for (int i = 0; i < N; i++) {
            printf("%d", numbers[i]);
        }
    }

    return 0;
}