#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
long long int* arr = new long long int[n];
long long int count = 0;
for (int i = 0; i < n;i++)
cin >> arr[i];
for (int i = 0;i < n;i++) {
count += arr[i];
}
while (count > 9) {
long long int sum = 0;
while (count != 0)
{
sum += count % 10;
count /= 10;
}
count = sum;
}
cout << count;
return 0;
}