N = int(input()) while N >= 10: N = sum(map(int, str(N))) print(N)