local mfl = math.floor
local n = io.read("*n")
local a = {}
for i = 1, n do
  a[i] = io.read("*n")
end

local function solve(x)
  if x == 1 then
    for i = 1, n - 1 do
      if a[i + 1] <= a[i] then return false end
    end
    return true
  end
  local tasks = {}
  local ok = true
  for i = 1, n do
    if 0 == #tasks or tasks[#tasks][1] < a[i] then
      table.insert(tasks, {a[i], 1})
    else
      while 0 < #tasks and a[i] < tasks[#tasks][1] do
        table.remove(tasks)
      end
      if 0 == #tasks then
        table.insert(tasks, {a[i], 2})
      elseif tasks[#tasks][1] == a[i] then
        tasks[#tasks][2] = tasks[#tasks][2] + 1
      else
        table.insert(tasks, {a[i], 2})
      end
      while 0 < #tasks do
        if x < tasks[#tasks][2] then
          local pos = tasks[#tasks][1]
          if pos == 1 then
            ok = false
            break
          else
            table.remove(tasks)
            if 0 < #tasks and tasks[#tasks][1] == pos - 1 then
              tasks[#tasks][2] = tasks[#tasks][2] + 1
            else
              table.insert(tasks, {pos - 1, 2})
              break
            end
          end
        else
          break
        end
      end
      if 0 == #tasks or tasks[#tasks][1] < a[i] then
        table.insert(tasks, {a[i], 1})
      end
    end
    if not ok then break end
  end
  return ok
end

local min, max = 0, n
while 1 < max - min do
  local mid = mfl((max + min) / 2)
  if solve(mid) then
    max = mid
  else
    min = mid
  end
end
print(max)
