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