n = int(input()) p = list(map(int, input().split())) while len(p) > 1: if len(p) % 2 == 1: p.append(1) q = list() for i in range(0,len(p),2): q.append(p[i+0]*p[i+1]) p = q ans = p[0] while ans >= 10: s = str(ans) ans = 0 for c in s: ans += ord(c) - ord('0') print(ans)