N = int(input()) a = N for _ in range(100): s = 0 while a: s += a % 10 a //= 10 a = s print(a)