import sys input=sys.stdin.readline def digitSum(n): if len(str(n)) is 1: return n dst = sum(list(map(int, str(n)))) return digitSum(dst) n = int(input()) result = digitSum(n) print(int(result))