import sys import numpy as np 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=np.prod(np.array(p, dtype='int64')) while not len(str(k))==1: k=sum(list(map(int, str(k)))) print(k)