n = input() ans = n while len(ans) != 1: s = 0 for i in ans: s += int(i) ans = str(s) print(ans)