#include <bits/stdc++.h>
#define REP(i,n)for (int i=0;i<(n);i++)
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ll long long
using namespace std;
bool ok(int a){
    vector<int>V;
    while(a > 0){
        V.PB(a%10);
        a /= 10;
    }
    if(V.size()==1)return true;
    REP(i,V.size()-1){
        if(V[i] - V[i+1] != 1)return false;
    }
    return true;
}
int main(){
    int n;
    int a[1000];
    cin >> n;
    REP(i,n)cin >> a[i];
    int ans=-1;
    REP(i,n)for(int j=i+1;j<n;j++){
        if(ans >= a[i] * a[j])continue;
        if(ok(a[i]*a[j])){
            ans = a[i] * a[j];
        }
    }
    cout<<ans<<endl;
}