n = int(input()) x = sum(list(map(int, str(n)))) while x >9: x = sum(list(map(int, str(x)))) print(x)