import math
from functools import reduce


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


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


n = int(input())
a_list = list(map(int, input().split(" ")))

max_iter = lcm(a_list)
# print(max_iter)

max_val = -1

for i in range(max_iter + 1):
    # print("===============")
    # print("Max val = {}, i = {}".format(max_val, i))
    val = sum([i % a for a in a_list])
    max_val = max(max_val, val)

print(max_val)