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

max = 0
i = lim
while i != 0:
  result = sum([i % j for j in ar])
  if result > max:
    max = result
  i -= 1
    
print(max)