n=int(input()) P=list(map(int,input().split())) cnt=1 for i in range(n): if P[i]==0: print(0) break cnt*=P[i] cnt%=9 print(cnt%9 if cnt!=0 else 9)