#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

ll check(ll a){
  ll now = a%10;
  ll ret = a;
  a/=10;
  while(a>0){
    if(now-1 != a%10)return -1;
    a/=10;
    now--;
  }
  return ret;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  vi A(n);
  for(auto &a:A)cin>>a;
  ll ans=-1;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      ans=max(ans,check(A[i]*A[j]));
    }
  }
  cout<<ans<<endl;
  return 0;
}

