import functools
n = int(input())
a_n = [int(x) for x in input().split()]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


def f(m):
    return sum([m % a for a in a_n])


def check_f(a_n):
    a_n.sort(reverse=True)
    max_num = lcm(a_n[0], a_n[1])
    return max([f(x) for x in range(max_num+1)])


print(check_f(a_n))
