import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val a = (0 until n).map { sc.next().toInt() }
    println(problem103c(n, a))
}

fun problem103c(n: Int, a: List<Int>): Int {
    val list = IntArray(Math.pow(10.0, 6.0).toInt())
    for (i in a.min()!! until Math.pow(10.0, 6.0).toInt()) {
        var sum = 0
        for (j in 0 until n) {
            sum += i % a[j]
        }
        list[i] = sum
    }
    return list.max()!!
}