import sys import heapq sys.set_int_max_str_digits(0) def d(x): return sum(int(c) for c in x) n = int(input()) x = list(map(int, input().split())) # ヒープキューを使って桁数の短いものから処理 heap = [str(num) for num in x] heapq.heapify(heap) while len(heap) > 1: # 一番短い2つを取り出して掛け算 a = heapq.heappop(heap) b = heapq.heappop(heap) product = str(int(a) * int(b)) # 結果をヒープに戻す(ソートの基準を桁数にする) heapq.heappush(heap, product) y = heap[0] # 桁数が1になるまで桁和を取る while len(y) != 1: y = str(d(y)) print(y)