from sys import stdin n = int(stdin.readline().rstrip()) a = list(map(int,stdin.readline().rstrip().split())) tmp=1 for i in range(n) : tmp *= a[i] while tmp>9: tmp = sum(list(map(int, str(tmp)))) print(tmp)