N=int(input()) P=list(map(int,input().split())) temp=1 for p in P: temp*=p while True: temp=list(str(temp)) if len(temp)==1: break ans=0 for item in temp: ans+=int(item) temp=ans print(*temp)