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 ans = solve(&a);
    println!("{}", ans);
}

fn solve(a: &Vec<usize>) -> usize {
    let mut ok = 1 << 60;
    let mut ng = 0;
    while ok - ng > 1 {
        let max = (ok + ng) / 2;
        if is_ok(&a, max) {
            ok = max;
        } else {
            ng = max;
        }
    }
    ok
}

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

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

impl State {
    fn new(max: usize, initial_size: usize) -> State {
        State {
            max: max,
            digits: vec![(0, initial_size)],
            length: initial_size,
        }
    }

    fn resize(&mut self, new_size: usize) {
        if new_size > self.length {
            let add = new_size - self.length;
            self.digits.push((0, add));
        } else {
            let mut reduce = self.length - new_size;
            while let Some((digit, count)) = self.digits.pop() {
                if count > reduce {
                    self.digits.push((digit, count - reduce));
                    break;
                }
                reduce -= count;
            }
        }
        self.length = new_size;
    }

    fn increment(&mut self) -> bool {
        let mut suffix = 0;
        while let Some((digit, count)) = self.digits.pop() {
            assert!(count > 0);
            if digit + 1 == self.max {
                suffix += count;
            } else {
                if count > 1 {
                    assert!(count - 1 > 0);
                    self.digits.push((digit, count - 1));
                }
                assert!(digit + 1 < self.max);
                self.digits.push((digit + 1, 1));
                if suffix > 0 {
                    self.digits.push((0, suffix));
                }
                return true;
            }
        }
        assert_eq!(suffix, self.length);
        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) -> IO<R, W> {
        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: 11376