n = int(input())
a = list(map(int, input().split()))
dp = [[[-1] * (5 * 10 ** 6) for _ in range(n)] for _ in range(2)]
dp[0][0][1000] = 0
dp[1][0][1000] = 0
for i in range(n):
    for j in range(5 * 10 ** 6):
        dp[0][i + 1][j], dp[1][i + 1][j] = dp[0][i][j], dp[1][i][j]
    for j in range(5 * 10 ** 6):
        u, v = dp[0][i][j], dp[1][i][j]
        if max(u, v) < 0:
            continue
        dp[0][i + 1][j] = u
        dp[1][i + 1][j] = v
        # print(i, j, u, v)
        dp[0][i + 1][j + max(u, v) * a[i]] = 0
        dp[1][i + 1][j % a[i]] = max(u, v) + j // a[i]
ans = 0
for j in range(10 ** 4):
    if dp[0][n][j] != -1 or dp[1][n][j] != -1:
        ans = max(ans, j)
print(ans)