#include<cstdio>
#include<algorithm>
using namespace std;
int force(int a[],int n,int p=0,int sum=0)
{
if(p>=n)
return sum;
int ns=sum+a[p],mx=0;
int d[10]={1,0};
while(ns)
{
d[d[0]]=ns%10;
ns/=10;
d[0]++;
}
sort(d+1,d+d[0]);
do
{
ns=0;
for(int i=1;i<d[0];i++)
ns=ns*10+d[i];
mx=max(mx,force(a,n,p+1,ns));
}while(next_permutation(d+1,d+d[0]));
return mx;
}
int main()
{
int n,i;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++)
scanf("%d",a+i);
int res=force(a,n);
printf("%d\n",res);
return 0;
}
I2luY2x1ZGU8Y3N0ZGlvPgojaW5jbHVkZTxhbGdvcml0aG0+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgZm9yY2UoaW50IGFbXSxpbnQgbixpbnQgcD0wLGludCBzdW09MCkKewogICAgaWYocD49bikKICAgICAgIHJldHVybiBzdW07CiAgICBpbnQgbnM9c3VtK2FbcF0sbXg9MDsKICAgIGludCBkWzEwXT17MSwwfTsKICAgIHdoaWxlKG5zKQogICAgewogICAgICAgIGRbZFswXV09bnMlMTA7CiAgICAgICAgbnMvPTEwOwogICAgICAgIGRbMF0rKzsKICAgIH0KICAgIHNvcnQoZCsxLGQrZFswXSk7CiAgICBkbwogICAgewogICAgICAgIG5zPTA7CiAgICAgICAgZm9yKGludCBpPTE7aTxkWzBdO2krKykKICAgICAgICAgICAgbnM9bnMqMTArZFtpXTsKICAgICAgICBteD1tYXgobXgsZm9yY2UoYSxuLHArMSxucykpOwogICAgfXdoaWxlKG5leHRfcGVybXV0YXRpb24oZCsxLGQrZFswXSkpOwogICAgcmV0dXJuIG14Owp9CgppbnQgbWFpbigpCnsKICAgIGludCBuLGk7CiAgICBzY2FuZigiJWQiLCZuKTsKICAgIGludCBhW25dOwogICAgZm9yKGk9MDtpPG47aSsrKQogICAgICAgIHNjYW5mKCIlZCIsYStpKTsKICAgIGludCByZXM9Zm9yY2UoYSxuKTsKICAgIHByaW50ZigiJWRcbiIscmVzKTsKICAgIHJldHVybiAwOwp9Cg==