n = int(input()) p = list(map(int, input().split())) while True: tmp = [] if len(p) % 2 == 1: tmp.append(p[-1]) for i in range(n//2): tmp.append(p[2*i]*p[2*i+1]) p = tmp[0:] n = len(p) if n == 1: ans = p[0] break while True: if len(str(ans)) == 1: print(ans) break tmp = 0 for i in str(ans): tmp += int(i) ans = tmp