#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
constexpr int gcd(int a,int b){return b?gcd(b,a%b):a;}
constexpr int lcm(int a,int b){return a*b/gcd(a,b);}

int main(){
    int n;
    cin>>n;
    vi v(n);
    rep(i,n){
        cin>>v[i];
    }
    vs s;
    string t="123456789";
    rep(i,n-1)range(j,i+1,n){
        string x=to_string(v[i]*v[j]);
        if(t.find(x)!=string::npos) s.push_back(x);
    }
    sort(all(s),[](string a,string b){
        return a.length()>b.length() || (a.length()==b.length() && a[0]>b[0]);
    });
    if(s.size()){
        cout<<s[0]<<endl;
    }else{
        cout<<-1<<endl;
    }
}