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

int N;
int arr[1010];

int main() {
    cin >> N; 
    for (int j = 0; j < N; ++j) {
        cin >> arr[j];
    }
    int val = -1;
    for (int j = 0; j < N; ++j) {
        for (int k = j+1; k < N; ++k) {
            int prod = arr[j] * arr[k];

            bool valid = true;
            int prev_dig = prod % 10;
            for (int tmp = prod/10; tmp > 0; tmp /= 10, --prev_dig) {
                int dig = tmp % 10;
                if (dig != prev_dig-1) {
                    valid = false;
                    break;
                }
            }

            if (valid) {
                val = max(val, prod);
            }
        }
    }
    cout << val << endl;
    return 0;
}