n=int(input()) lst=[0]*100 lst[0]=n for i in range(100): s = 0 for j in str(lst[i]): s+=int(j) if i<99:lst[i+1]=s else: print(lst[i]) exit()