from numpy import prod input() a=prod(list(map(int,input().split()))) while a>9: a=sum([int(x) for x in str(a)]) print(a)