#include<bits/stdc++.h>
using namespace std;

#define FOR(i, a, n) for(int i = (a); i < (n); i++)
#define REP(i, n) FOR(i, 0, (n))
#define ALL(a) (a.begin(), a.end())
typedef vector<int> vi;
bool check(int a)
{
    string s = to_string(a);
    REP(i, s.size()-1)
    {
        if(s[i+1]-s[i] != 1) return false;
    }
    return true;
}

int main()
{
    int n;
    cin>>n;
    vector<int> v(n);
    REP(i, n) cin>>v[i];
    int ans = -1;
    vector<pair<int, vector<int>>> kouho;
    REP(i, n)REP(j, i)
    {
        if(v[i] == 0 || v[j] == 0) continue;
        int t = v[i] * v[j];
        if(check(t))
        {
            ans = max(ans, t);
            kouho.emplace_back(t, vi{i, j});
        }
    }
    bool update = true;
    while(update)
    {
        update = false;
        REP(i, kouho.size())
        {
            int a = kouho[i].first;
            vi w = kouho[i].second;
            REP(j, n)
            {
                bool f = false;
                REP(k, w.size())
                {
                    if(w[k] == j) f = true;
                }
                if(f) break;
                int t = a * v[j];
                if(check(t))
                {
                    update = true;
                    ans = max(ans, t);
                    vi x = w;
                    x.push_back(j);
                    kouho.emplace_back(t, x);
                }
            }
        }
    }
    cout << ans << endl;
}