n = list(map(int, list(input()))) while True: if len(n) == 1: break n = list(map(int, list(str(sum(n))))) print(n[0])