def main(): N = int(input()) for i in range(len(str(N))): num = 0 for j in str(N): num += int(j) N = num print(num) if __name__ == '__main__': main()