#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Ti = tuple<int, int, int>;
using Tl = tuple<ll, ll, ll>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define Get(t, i) get<(i)>((t))
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for(auto& a : b)

const int inf = 1 << 25;
const ll INF = 1LL << 55;

int main()
{
  int N; cin >> N;
  int a[1001];
  rep(i, N) cin >> a[i];
  int ans = -1;
  rep(i, N) {
    rep(j, N) {
      if(i == j) continue;
      string s = to_string(a[i]*a[j]);
      bool flag = true;
      rep(k, s.size()-1) {
	if(s[k]+1 != s[k+1]) flag = false;
      }
      if(flag) ans = max(ans, a[i]*a[j]);
    }
  }
  cout << ans << endl;
  return 0;
}