fun c103(args: Array<String>) {
    val numList = args[1].split(" ").map { it.toInt() }
    val ansCandidateList = (2..1000000).map { x -> numList.map { x % it }.sum() }
    println(ansCandidateList.max())
}

fun main(args: Array<String>) {
    c103(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}