def d(num): total = 0 for digit in str(num): total += int(digit) return total n = int(input()) s = input().split() x = [] for i in s: x.append(int(i)) ans = 1 for i in x: ans *= i while ans>9: ans = d(ans) print(ans)