#include <iostream>
using namespace std;
int main() {
int n, sum = 0, temp;
cin >> n;
while (n--) {
cin >> temp;
while (temp > 0) {
sum += temp % 10;
temp /= 10;
}
}
if (sum < 10) {
cout << sum;
return 0;
}
int ans = sum;
while (ans >= 10) {
sum = 0;
while (ans >= 1) {
sum += ans % 10;
ans /= 10;
}
ans = sum;
}
cout << ans;
}