num = input()
while True:
if len(num) > 1:
num = str(sum(list(map(int, list(num)))))
else:
print(num)
break
num = input()
while True:
if len(num) > 1:
num = str(sum(list(map(int, list(num)))))
else:
print(num)
break