n = int(input()) while n > 9: n = sum(list(map(int, str(n)))) print(n)