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