input() a=eval(input().replace(' ','*')) while a>9: a=sum([int(x) for x in str(a)]) print(a)