object Main extends App{
  import scala.io.StdIn._
  val Array(n, m) = readLine().split(' ').map(_.toInt)
  solve(n, m)

  def solve(n:Int, m:Int):Unit = {
    if (n == 0 && m == 0) return
    val strength = readLine().split(' ').map(_.toInt)
    val boss = strength.last
    val enemy = strength.toList
    if (minBattle(enemy, 1, boss) < m) println(-1)
    else {
      var min = strength.head - 1
      var max = strength.last
      var mid = 0
      while (min < max) {
        mid = (min + max + 1) / 2
        if (minBattle(enemy, mid, boss) >= m) {
          min = mid
        } else {
          max = mid - 1
        }
      }
      println(if (minBattle(enemy, min, boss) >= m) min else -1)
    }
    val Array(nn, mm) = readLine().split(' ').map(_.toInt)
    solve(nn, mm)
  }

  def max(i: Int, i1: Int) = if (i > i1) i else i1
  def minBattle(enemy:List[Int], x:Int, boss:Int, level:Int = 1, battleCount:Int = 1):Int = {
    if (level + x > boss) return battleCount
    def lowerAndHigher(e:List[Int]):(Option[Int], Int, List[Int]) = {
      e match{
        case l::h::t if l > level => (None, l, (h::t))
        case l::h::t if l <= level && level < h => (Some(l), h, t)
        case h::Nil => (None, h, Nil)
        case _::t => lowerAndHigher(t)
        case _ => ???
      }
    }
    def score(e:Int) = if (x - (e - level).abs > 0) x - (e - level).abs else 1
    lowerAndHigher(enemy) match{
      case (None, higher, rest) if (higher < level + x)=>{
        val diff = x - higher + level
        var i = 1
        var bc = battleCount + 1
        while (diff * i + level <= higher){
          i = i * 2 + 1
          bc += 1
        }
        return minBattle((higher::rest), x, boss, level + diff * i, bc)
      }
      case (Some(lower), higher, rest) if (higher >= level + x) =>
        if (lower + x <= level)
          minBattle(higher::rest, x, boss, higher - x + 1, battleCount + higher - x + 1 - level)
        else
          minBattle(lower::higher::rest, x, boss, lower + x, battleCount + 1)
      case (Some(lower), higher, rest) =>
        if (score(lower) > score(higher)){
          minBattle(lower::higher::rest, x, boss, lower + x, battleCount + 1)
        }else{
          val diff = x - higher + level
          var i = 1
          var bc = battleCount + 1
          while (diff * i + level <= higher){
            i = i * 2 + 1
            bc += 1
          }
          return minBattle((higher::rest), x, boss, level + diff * i, bc)
        }
    }
  }
}

