ns, _hs, *_ = ARGF.read.split("\n").map { |e| e.split }
hs = _hs.map { |e| e.to_i }
i = 0
as = hs.map {
  0
}
loop {
  ps = hs.zip(as).map { |e|
    h, a = e
    h - a
  }
  # p ps
  if ps.reduce(0) { |acc, e| acc + e } == 0
    puts i
    exit
  end
  flag = false
  ps.map.with_index { |e, i|
    if e == 0
      if flag
        break
      end
    else
      as[i] += 1
      flag = true
    end
    
  }
  i += 1
}
