import kotlin.math.max fun calMax(m: Int, current: Int, currentMax: Int, mods: IntArray): Int { if (m == mods.lastIndex) { return max(currentMax, current % mods.last()) } if (current < currentMax) return currentMax return calMax(m + 1, current, calMax(m + 1, current % mods[m], currentMax, mods), mods) } fun main() { val (n, k) = readLine()!!.trim().split(' ').map(String::toInt) val mods = readLine()!!.trim().split(' ').map(String::toInt).sortedDescending().toIntArray() println(calMax(0, k, 0, mods)) }