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