N = int(input()) def fun(N): for i in range(10): if N % (10**i) != N: x = i+1 a = 0 c = 0 for j in range(1,x+1): a = int(((N-a) % (10**j)) / 10**(j-1)) b = a c = b + c #print(c) return c if N < 10: print(N) if fun(N) > 10: print(fun(fun(N)) )