n = list(map(int,list(input()))) for i in range(100): n = list(map(int,list(str(sum(n))))) print(n[0])