N = input() ans = 1 for p in map(int, input().split()): if p: ans *= p ans %= 9 else: print(0) exit() print((ans - 1) % 9 + 1)