#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

bool check(int x){
    int p = x % 10;
    x /= 10;
    bool f = 1;
    while (x) {
        if (x % 10 != p - 1) f = 0;
        x /= 10;
        p--;
    }
    return f;
}

int main() {
    int n;
    cin >> n;
    VI a(n);
    REP(i,n) cin >> a[i];

    int ans = -1;
    REP(i,n-1) FOR(j,i+1,n-1){
        int x = a[i]*a[j];
        if (check(x)) ans = max(ans, x);
    }

    cout << ans << endl;

    return 0;
}