import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Queue, PriorityQueue}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N, K = in.next().toInt
  val A = new Array[Int](N+1)
  for (i <- 1 to N) {
    A(i) = in.next().toInt
  }

  //
  val sum = A.sum

  var divisors: List[Int] = Nil
  var ind = 1
  while(ind * ind <= sum) {
    if (sum % ind == 0) {
      divisors = ind :: (sum / ind) :: divisors
    }
    ind += 1
  }

  divisors = divisors.sorted.reverse

  //
  var ans = -1
  breakable {
    for (e <- divisors) {
      var now = A.map(_ % e).sorted
      var small = 0
      var large = now.map(e - _).sum

      for (i <- 0 to N) {
        small += now(i)
        large -= e - now(i)

        val tmp = small min large
        val tmp2 = Math.abs(small - large)

        if(tmp + tmp2 <= K && tmp2 % e == 0) {
          ans = e
          break
        }
      }
    }
  }

  println(ans)
}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}
