#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
long long maxone = 0;
cin >> n;
vector<char> v(n);
for (int i=0; i<n; i++) cin >> v[i];
do {
string s, s1;
for (int i=0, j=n-1; i<=j; i++, j--) {
if (i == j) s1 += v[i];
else s += v[i], s1 += v[j];
}
reverse(s1.begin(), s1.end());
if (s[0] != '0' && s1[0] != '0')
maxone = max(stoll(s) * stoll(s1), maxone);
} while (next_permutation(v.begin(), v.end()));
cout << maxone;
}