#include<bits/stdc++.h>
#define MAX 1024
#define inf 1<<29
#define linf 1e18
#define eps (1e-8)
#define mod 1000000007
#define pi M_PI
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.10f\n",(double)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a)-1;(b)<=i;i--)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<double,int> pdi;
typedef vector<int> vi;
typedef vector<pii> vpi;
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

bool check(int a){
  ostringstream os;
  os<<a;
  string s=os.str();
  FOR(i,1,s.length())if(s[i]!=s[i-1]+1)return false;
  return true;
}

int main()
{
  int n,a[MAX],ans=-1;

  cin>>n;
  FOR(i,0,n)cin>>a[i];

  FOR(i,0,n){
    FOR(j,i+1,n){
      int pro=a[i]*a[j];
      if(check(pro))ans=max(ans,pro);
    }
  }
  cout<<ans<<endl;
  return 0;
}