while True:
n = int(input())
if n >=1 and n<=10**5:
break
l = (input())
l = l.split(" ")
if len(l) == n:
sm = 0
flag=True
for i in range (len(l)):
if int(l[i])>=0 and int(l[i])<=10**18:
sm += int(l[i])
else:
flag=False
if flag:
if sm < 10:
print (sm)
else:
while True:
x = str(sm)
sm = 0
for i in range (len(x)):
sm += int(x[i])
if sm < 10:
print (sm)
break