N = int(input()) P = list(map(int, input().split())) K = 1 for i in P: K *= i while len(str(K)) != 1: K = sum(list(map(int, list(str(K))))) print(K)