n = int(input()) new=n for a in range(100): suum=0 if (new<10): break new=str(new) for i in new: suum+=int(i) new=int(new) new=suum print(new)