import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) import numpy as np n = int(readline()) k = np.array(list(map(int, read().split())), dtype=np.int64).prod() k = str(sum(map(int, str(k)))) while len(k) != 1: k = str(sum(map(int, k))) print(k)