import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) n, *p = map(int, read().split()) k = 1 for pp in p: k *= pp k = str(sum(map(int, str(k)))) while len(k) != 1: k = str(sum(map(int, k))) print(k)