#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int a[1000];
int main() {
	int n; scanf("%d\n", &n);
	rep(i, n)scanf("%d", &a[i]);
	int Max = -1;
	rep(i, n)rep(j, n) {
		if (i == j)continue;
		string s = to_string(a[i]*a[j]);
		char back = 0;
		bool ok = true;
		for (char c : s) {
			if (back&&back + 1 != c)ok = false;
			back = c;
		}
		if (ok)Max = max(Max, stoi(s));
	}
	printf("%d\n", Max);
}