fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let a: Vec<usize> = sc.vec(n);

    let mut ok = n + 1;
    let mut ng = 0;
    while ok - ng > 1 {
        let max = (ok + ng) / 2;
        if solve(&a, max) {
            ok = max;
        } else {
            ng = max;
        }
    }
    println!("{}", ok);
}

fn solve(a: &Vec<usize>, max: usize) -> bool {
    let mut state = State::new();
    let mut prev = 0;
    for &a in a.iter() {
        state.resize(a);
        if a <= prev {
            if !state.increment(max) {
                return false;
            }
        }
        prev = a;
    }
    true
}

struct State {
    length: usize,
    content: Vec<(usize, usize)>,
}

impl State {
    fn new() -> Self {
        State {
            length: 0,
            content: Vec::new(),
        }
    }

    fn resize(&mut self, new_size: usize) {
        if new_size > self.length {
            let add = new_size - self.length;
            self.content.push((0, add));
            self.length = new_size;
        } else {
            let mut reduce = self.length - new_size;
            while reduce > 0 {
                let (c, num) = self.content.pop().unwrap();
                if reduce >= num {
                    reduce -= num;
                } else {
                    self.content.push((c, num - reduce));
                    reduce = 0;
                }
            }
            self.length = new_size;
        }
    }

    fn increment(&mut self, max: usize) -> bool {
        let mut suffix = 0;
        while let Some((c, num)) = self.content.pop() {
            if c + 1 == max {
                suffix += num;
            } else {
                assert!(num > 0);
                if num > 1 {
                    self.content.push((c, num - 1));
                }
                self.content.push((c + 1, 1));
                if suffix > 0 {
                    self.content.push((0, suffix));
                }
                return true;
            }
        }
        false
    }
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 11372