# -*- coding: utf-8 -*-
"""
Created on Mon Aug  6 17:15:00 2018

@author: Yuki
"""

N = int(input())

A = list(input().split())
A = [int(i) for i in A]

def get_f_value(m, A):
    mod_list = [m%i for i in A]
    return sum(mod_list)

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

def get_lcm_from_list(A):
    lcm_list = [lcm(A[i], A[i+1]) for i in range(len(A)-1)]
    return max(lcm_list)

lcm_value = get_lcm_from_list(A)
res = []
for m in range(lcm_value):
    res.append(get_f_value(m, A))
print(max(res))
