n = int(input()) p = list(map(int, input().split())) MOD = 9 ans = 1 for i in range(n): if p[i] == 0: print(0) exit() ans *= p[i] ans = max(ans % MOD, 1) print(ans)