n = int(input()) res = 0 while True: if res == 0: res = sum([int(x) for x in str(n)]) else: res = sum([int(x) for x in str(res)]) if res < 10: break print(res)