#include<iostream>
#include<vector>
using namespace std;
int digit_sum(int x) {
int temp=0;
int sum = 0;
while (x > 0)
{
sum = x % 10 + sum;
x = x / 10;
}
return sum;
}
int main() {
int max = 0;
int maxindex = 0;
int num;
int res=0;
cin >> num;
vector<int> arr(num);
vector<int> temp(num);
vector<int> maxtemp(num);
for (int i = 0; i < num; i++)
{
cin >> arr[i];
}
for (int i = 0; i < num; i++)
{
temp[i]=digit_sum(arr[i]);
}
for (int i = 0; i < num; i++)
{
if (max < temp[i])
{
max = temp[i];
res = arr[i];
}
else if(temp[i]==max)
{
if(res<arr[i])
{
res=arr[i];
}
}
}
cout << res;
}