def sum_digit(x):
sum = 0
while(x>0):
r = x%10
sum+=r
x = x // 10
return sum
def sum_list(x):
sum = 0
l = len(x)
for i in range(0,l):
sum = sum + int(x[i])
return sum
tc = int(input())
num = 0
x = input()
lis = x.split(" ")
num = int(sum_list(lis))
while(num>9):
num = sum_digit(num)
print(num)