s = list(map(int,input())) while len(s) >1: a = sum(s) s = list(map(int,str(a))) print(s[0])