import math

input()

nums = list(map(int,input().split()))

def lcm(a,b):
	return a*b//math.gcd(a,b)
	
N=nums[0]
for i in range(1,len(nums)):
	N=lcm(N,nums[i])

M=0
for i in range(1,N+1):
	cnt=0
	tmp = sum([i%num for num in nums])
	if M < tmp:
		M=tmp
		

print(M)