import functools
N = int(input())
ar = [int(i) for i in input().split()]
lim = functools.reduce(lambda x, y: x * y, ar)

nums = list(range(1,lim))
nums.reverse()
max = 0
for i in nums:
  result = sum([i % j for j in ar])
  if result > max:
    max = result
    
print(max)