N = int(input()) P = list(map(int, input().split())) K = 1 for p in P: K *= p age = K while len(str(age)) > 1: tmp = [int(s) for s in str(age)] age = sum(tmp) print(age)