import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines n=int(input()) p=list(map(int, input().split())) k=1; for pp in p: k*=pp while not len(str(k))==1: k=sum(list(map(int, str(k)))) print(k)