N = int(input()) P = list(map(int,input().split())) A = 1 for i in P: A *= i while A > 9: A = sum(map(int, list(str(A)))) print(A)