n = int(input()) print(n%9 if n%9>0 else 9)