#include<bits/stdc++.h>

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)

using namespace std;

bool check(int v) {
  stringstream ss;
  ss << v;
  string tmp;
  ss >> tmp;
  REP(i,1,(int)tmp.size()) {
    if( tmp[i-1]+1 != tmp[i] ) {
      return false;
    }
  }
  return true;
}

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  rep(i,N) cin >> vec[i];
  int maxi = -1;
  rep(i,N) {
    REP(j,i+1,N) {
      int tmp = vec[i] * vec[j];
      if( check(tmp) ) {
        maxi = max(maxi,tmp);
      }
    }
  }
  cout << maxi << endl;
  return 0;
}