# coding: utf-8 # Your code here! import sys sys.setrecursionlimit(10**6) readline = sys.stdin.readline #h,w,k = [int(i) for i in readline().split()] #n = int(input()) #ab = [[int(i) for i in readline().split()] for _ in range(n)] n = int(input()) a = [int(i) for i in readline().split()] ans = 1 ok = 1 for i in a: ans *= i ans %= 9 if not i: ok = 0 if ok: print(ans if ans != 0 else 9) else: print(0)