#include <iostream>
#include <vector>
using namespace std;
int main()
{
int n,a;
cin>>n;
int sum = 0;
for(int i = 0 ; i < n ; i++)
{
cin>>a;
sum+=a;
}
while(!(sum<=9 && sum>=0))
{
vector <int> d;
int temp = sum;
int z = 0;
while(temp)
{
d.push_back(temp%10);
temp = temp/10;
}
for(int i = 0; i <d.size(); i++)
{
z+=d[i];
}
sum = z;
}
cout<<sum;
return 0;
}