import math
from functools import reduce
n=int(input())
a=list(map(int,input().split()))


def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


p=lcm_list(a)

x=[]
for i in range(p,1,-1):
  y=0
  for j in a:
    z=(i%j)
    y+=z
  x.append(y)


print(max(x))