input() a=sum(map(int,input().split())) while a>9: a=sum([int(x) for x in str(a)]) print(a)