n = int(input())
while n>= 10:
    total = 0
    while n>0:
        num = n%10
        total += num
        n = n//10
    n = total

print(n)