//BRUTE FORCE
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define all(x) x.begin(), x.end()
using namespace std;
const int maxn = 1e5 + 1;
ll A[maxn];
vector<ll> D[46];
pair<ll, ll> scs[maxn];
int sumDigit(int n) {
int s = 0;
while (n != 0) {
s += n % 10;
n /= 10;
}
return s;
}
int cntDigit(int n) {
int cnt = 0;
while (n != 0) {
cnt++;
n /= 10;
}
return cnt;
}
ll lt[12];
void tenEn() {
lt[0] = 1;
for (int i = 1; i <= 10; ++i) {
lt[i] = lt[i - 1] * 10;
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// freopen("file.inp","r",stdin);
// freopen("file.out","w",stdout);
tenEn();
int n;
ll res = 0;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> A[i];
D[sumDigit(A[i])].push_back(A[i]);
}
for (int i = 0; i <= 45; ++i) {
if (D[i].size() < 2) continue;
for (int j = 0; j < D[i].size(); ++j) {
scs[j].first = cntDigit(D[i][j]); scs[j].second = D[i][j];
}
for (int j = 0; j < D[i].size(); ++j) {
for (int k = j + 1; k < D[i].size(); ++k) {
ll a = (scs[j].second * lt[cntDigit(scs[k].second)] + scs[k].second);
ll b = (scs[k].second * lt[cntDigit(scs[j].second)] + scs[j].second);
res = max(res, max(a, b));
}
}
}
cout << res;
}
Ly9CUlVURSBGT1JDRQojaW5jbHVkZTxiaXRzL3N0ZGMrKy5oPgojZGVmaW5lIHVsbCB1bnNpZ25lZCBsb25nIGxvbmcKI2RlZmluZSBsbCBsb25nIGxvbmcKI2RlZmluZSBhbGwoeCkgeC5iZWdpbigpLCB4LmVuZCgpCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmNvbnN0IGludCBtYXhuID0gMWU1ICsgMTsKbGwgQVttYXhuXTsKdmVjdG9yPGxsPiBEWzQ2XTsKcGFpcjxsbCwgbGw+IHNjc1ttYXhuXTsKaW50IHN1bURpZ2l0KGludCBuKSB7CiAgICBpbnQgcyA9IDA7CiAgICB3aGlsZSAobiAhPSAwKSB7CiAgICAgICAgcyArPSBuICUgMTA7CiAgICAgICAgbiAvPSAxMDsKICAgIH0KICAgIHJldHVybiBzOwp9CmludCBjbnREaWdpdChpbnQgbikgewogICAgaW50IGNudCA9IDA7CiAgICB3aGlsZSAobiAhPSAwKSB7CiAgICAgICAgY250Kys7CiAgICAgICAgbiAvPSAxMDsKICAgIH0KICAgIHJldHVybiBjbnQ7Cn0KbGwgbHRbMTJdOwp2b2lkIHRlbkVuKCkgewogICAgbHRbMF0gPSAxOwogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gMTA7ICsraSkgewogICAgICAgIGx0W2ldID0gbHRbaSAtIDFdICogMTA7CiAgICB9Cn0KaW50IG1haW4oKSB7CiAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKDApOyBjaW4udGllKDApOyBjb3V0LnRpZSgwKTsKICAgIC8vIGZyZW9wZW4oImZpbGUuaW5wIiwiciIsc3RkaW4pOwogICAgLy8gZnJlb3BlbigiZmlsZS5vdXQiLCJ3IixzdGRvdXQpOwogICAgdGVuRW4oKTsKICAgIGludCBuOwogICAgbGwgcmVzID0gMDsKICAgIGNpbiA+PiBuOwogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgKytpKSB7CiAgICAgICAgY2luID4+IEFbaV07CiAgICAgICAgRFtzdW1EaWdpdChBW2ldKV0ucHVzaF9iYWNrKEFbaV0pOwogICAgfQogICAgZm9yIChpbnQgaSA9IDA7IGkgPD0gNDU7ICsraSkgewogICAgICAgIGlmIChEW2ldLnNpemUoKSA8IDIpIGNvbnRpbnVlOwogICAgICAgIGZvciAoaW50IGogPSAwOyBqIDwgRFtpXS5zaXplKCk7ICsraikgewogICAgICAgICAgICBzY3Nbal0uZmlyc3QgPSBjbnREaWdpdChEW2ldW2pdKTsgc2NzW2pdLnNlY29uZCA9IERbaV1bal07CiAgICAgICAgfQogICAgICAgIGZvciAoaW50IGogPSAwOyBqIDwgRFtpXS5zaXplKCk7ICsraikgewogICAgICAgICAgICBmb3IgKGludCBrID0gaiArIDE7IGsgPCBEW2ldLnNpemUoKTsgKytrKSB7CiAgICAgICAgICAgICAgICBsbCBhID0gKHNjc1tqXS5zZWNvbmQgKiBsdFtjbnREaWdpdChzY3Nba10uc2Vjb25kKV0gKyBzY3Nba10uc2Vjb25kKTsKICAgICAgICAgICAgICAgIGxsIGIgPSAoc2NzW2tdLnNlY29uZCAqIGx0W2NudERpZ2l0KHNjc1tqXS5zZWNvbmQpXSArIHNjc1tqXS5zZWNvbmQpOwogICAgICAgICAgICAgICAgcmVzID0gbWF4KHJlcywgbWF4KGEsIGIpKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KICAgIGNvdXQgPDwgcmVzOwp9