#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>

using namespace std;
using ll = long long;

bool check(const ll n)
{
    const string s = to_string(n);
    for (int i = 0; i < (int)s.size() - 1; i++) {
        if (s[i + 1] - s[i] != 1) {
            return false;
        }
    }
    return true;
}

int main()
{
    int N;
    cin >> N;
    vector<ll> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    constexpr ll INF = -1;
    ll mini = INF;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            const ll p = a[i] * a[j];
            if (check(p)) {
                mini = max(mini, p);
            }
        }
    }
    cout << mini << endl;
    return 0;
}