n=int(input()) t=tuple(map(int,input().split())) x=1 for i in t: x*=i while x>=10: x=sum(int(i) for i in str(x)) print(x)