N = int(input()) mod = N % 9 print(9 if mod == 0 and N != 0 else mod)